mirror of
https://github.com/kou029w/quot.git
synced 2025-01-31 14:28:06 +00:00
Compare commits
No commits in common. "787f97dcd7bc89b3a3a293e15bba51f778c3361a" and "2e05578e9ac4bf22fe9f988841f9f6116908541b" have entirely different histories.
787f97dcd7
...
2e05578e9a
7 changed files with 206 additions and 673 deletions
|
@ -7,17 +7,15 @@ interface Config {
|
|||
apiEndpoint: string;
|
||||
viewsDir: string;
|
||||
rootUrl: URL;
|
||||
openid:
|
||||
| false
|
||||
| {
|
||||
issuer: string;
|
||||
client: {
|
||||
client_id: string;
|
||||
client_secret: string;
|
||||
};
|
||||
request: HttpOptions;
|
||||
};
|
||||
key: false | KeyObject;
|
||||
openid: {
|
||||
issuer: string;
|
||||
client: {
|
||||
client_id: string;
|
||||
client_secret: string;
|
||||
};
|
||||
request: HttpOptions;
|
||||
};
|
||||
key: KeyObject;
|
||||
}
|
||||
|
||||
export type { Config };
|
||||
|
@ -33,20 +31,18 @@ function defaultConfig(): Config {
|
|||
apiUrl: new URL(process.env.QUOT_API_URL ?? "http://127.0.0.1:3000"),
|
||||
apiEndpoint: process.env.QUOT_API_ENDPOINT ?? "/api",
|
||||
viewsDir: "views",
|
||||
openid: Boolean(process.env.QUOT_OPENID_ISSUER) && {
|
||||
issuer: process.env.QUOT_OPENID_ISSUER!,
|
||||
openid: {
|
||||
issuer: process.env.QUOT_OPENID_ISSUER ?? "",
|
||||
client: {
|
||||
client_id: process.env.QUOT_OPENID_CLIENT_ID!,
|
||||
client_secret: process.env.QUOT_OPENID_CLIENT_SECRET!,
|
||||
client_id: process.env.QUOT_OPENID_CLIENT_ID ?? "",
|
||||
client_secret: process.env.QUOT_OPENID_CLIENT_SECRET ?? "",
|
||||
},
|
||||
request: { timeout: 5_000 },
|
||||
},
|
||||
key:
|
||||
Boolean(process.env.QUOT_JWK) &&
|
||||
crypto.createPrivateKey({
|
||||
key: JSON.parse(process.env.QUOT_JWK!),
|
||||
format: "jwk",
|
||||
}),
|
||||
key: crypto.createPrivateKey({
|
||||
key: JSON.parse(process.env.QUOT_JWK ?? "{}"),
|
||||
format: "jwk",
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -3,21 +3,9 @@ import { SignJWT } from "jose";
|
|||
import type { FastifyInstance } from "fastify";
|
||||
|
||||
async function login(fastify: FastifyInstance) {
|
||||
const key = fastify.config.key;
|
||||
if (!key) {
|
||||
fastify.log.warn("The key is required to use login endpoint.");
|
||||
return;
|
||||
}
|
||||
const openid = fastify.config.openid;
|
||||
if (!openid) {
|
||||
fastify.log.warn(
|
||||
"The openid parameters is required to use login endpoint."
|
||||
);
|
||||
return;
|
||||
}
|
||||
custom.setHttpOptionsDefaults(openid.request);
|
||||
const issuer = await Issuer.discover(openid.issuer);
|
||||
const client = new issuer.Client(openid.client);
|
||||
custom.setHttpOptionsDefaults(fastify.config.openid.request);
|
||||
const issuer = await Issuer.discover(fastify.config.openid.issuer);
|
||||
const client = new issuer.Client(fastify.config.openid.client);
|
||||
|
||||
fastify.get("/login", async (request, reply) => {
|
||||
const params = client.callbackParams(request.raw);
|
||||
|
@ -34,7 +22,7 @@ async function login(fastify: FastifyInstance) {
|
|||
.setProtectedHeader({ typ: "JWT", alg: "RS256" })
|
||||
.setExpirationTime("30days")
|
||||
.setSubject(userUrl.href)
|
||||
.sign(key);
|
||||
.sign(fastify.config.key);
|
||||
const url = new URL(fastify.config.rootUrl);
|
||||
url.hash = new URLSearchParams({ jwt }).toString();
|
||||
return reply.redirect(url.href);
|
||||
|
|
796
app/package-lock.json
generated
796
app/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -13,19 +13,18 @@
|
|||
"dependencies": {
|
||||
"@exampledev/new.css": "^1.1.3",
|
||||
"@fastify/http-proxy": "^8.2.2",
|
||||
"@lexical/history": "^0.4.1",
|
||||
"@lexical/plain-text": "^0.4.1",
|
||||
"esbuild": "^0.15.7",
|
||||
"@lexical/plain-text": "^0.3.11",
|
||||
"esbuild": "^0.15.5",
|
||||
"esbuild-register": "^3.3.3",
|
||||
"fastify": "^4.5.3",
|
||||
"jose": "^4.9.2",
|
||||
"lexical": "^0.4.1",
|
||||
"lexical": "^0.3.11",
|
||||
"openid-client": "^5.1.9",
|
||||
"solid-js": "^1.5.4"
|
||||
"solid-js": "^1.4.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node18-strictest-esm": "^1.0.1",
|
||||
"@types/node": "^18.7.15",
|
||||
"typescript": "^4.8.2"
|
||||
"@tsconfig/node18-strictest-esm": "^1.0.0",
|
||||
"@types/node": "^18.7.8",
|
||||
"typescript": "^4.7.4"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import {
|
|||
$getRoot,
|
||||
createEditor,
|
||||
} from "lexical";
|
||||
import { registerHistory, createEmptyHistoryState } from "@lexical/history";
|
||||
import { registerPlainText } from "@lexical/plain-text";
|
||||
import { onCleanup, onMount } from "solid-js";
|
||||
import type Pages from "../../protocol/pages";
|
||||
|
@ -35,7 +34,6 @@ export default (props: {
|
|||
root.append(paragraphNode);
|
||||
};
|
||||
onCleanup(registerPlainText(editor, initialEditorState));
|
||||
onCleanup(registerHistory(editor, createEmptyHistoryState(), 333));
|
||||
onMount(() => {
|
||||
onCleanup(
|
||||
editor.registerTextContentListener((text) => {
|
||||
|
|
|
@ -11,12 +11,13 @@ async function updatePage(
|
|||
content: Pages.RequestContentPage
|
||||
): Promise<boolean> {
|
||||
const jwt = window.localStorage.getItem("jwt");
|
||||
if (!jwt) return false;
|
||||
const res = await fetch(
|
||||
`${import.meta.env.QUOT_API_ENDPOINT}/pages?id=eq.${id}`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: {
|
||||
...(jwt ? { authorization: `Bearer ${jwt}` } : {}),
|
||||
authorization: `Bearer ${jwt}`,
|
||||
"content-type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(content),
|
||||
|
@ -27,11 +28,12 @@ async function updatePage(
|
|||
|
||||
async function deletePage(id: number): Promise<boolean> {
|
||||
const jwt = window.localStorage.getItem("jwt");
|
||||
if (!jwt) return false;
|
||||
const res = await fetch(
|
||||
`${import.meta.env.QUOT_API_ENDPOINT}/pages?id=eq.${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: jwt ? { authorization: `Bearer ${jwt}` } : {},
|
||||
headers: { authorization: `Bearer ${jwt}` },
|
||||
}
|
||||
);
|
||||
return res.ok;
|
||||
|
|
|
@ -22,8 +22,8 @@ services:
|
|||
restart: unless-stopped
|
||||
ports: ["3000:3000"]
|
||||
environment:
|
||||
QUOT_JWK: ${QUOT_JWK:?} # https://mkjwk.org
|
||||
DATABASE_URL: postgresql://postgres:${POSTGRES_PASSWORD}@/postgres?host=/var/run/postgresql
|
||||
PGRST_DB_ANON_ROLE: postgres
|
||||
volumes:
|
||||
- postgres_socket:/var/run/postgresql
|
||||
depends_on:
|
||||
|
|
Loading…
Add table
Reference in a new issue