mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-22 12:03:25 -04:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
7153f718fe
@ -7,11 +7,9 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare-dev": "nuxi prepare && pnpm run-file locale/generateSchemas.ts",
|
"prepare-dev": "nuxi prepare && pnpm run-file locale/generateSchemas.ts",
|
||||||
"dev": "nuxi dev",
|
"dev": "nuxi dev",
|
||||||
"build": "NODE_OPTIONS=\"--max-old-space-size=5120\" nuxt build",
|
"build": "NODE_OPTIONS=\"--max-old-space-size=5120\" nuxi build",
|
||||||
"start": "nuxt start",
|
|
||||||
"export": "nuxt export",
|
|
||||||
"serve": "nuxt serve",
|
|
||||||
"run-file": "node --import=./server/ts-node-esm.js --env-file=.env",
|
"run-file": "node --import=./server/ts-node-esm.js --env-file=.env",
|
||||||
|
"typecheck": "nuxi typecheck",
|
||||||
"lint": "eslint . --fix",
|
"lint": "eslint . --fix",
|
||||||
"test": "vitest"
|
"test": "vitest"
|
||||||
},
|
},
|
||||||
|
@ -66,6 +66,7 @@ const shoot = async (db: Database, mode: 'light' | 'dark'): Promise<void> => {
|
|||||||
authenticated: true,
|
authenticated: true,
|
||||||
},
|
},
|
||||||
'15m',
|
'15m',
|
||||||
|
process.env.NUXT_PUBLIC_DOMAIN_BASE ?? '',
|
||||||
);
|
);
|
||||||
|
|
||||||
pr.source(`${urlBases[locale] + username}?token=${encodeURIComponent(token)}`, ['1024x300'], {
|
pr.source(`${urlBases[locale] + username}?token=${encodeURIComponent(token)}`, ['1024x300'], {
|
||||||
|
@ -66,7 +66,7 @@ async function initTestDatabase(): Promise<string> {
|
|||||||
authenticated: true,
|
authenticated: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const token = await jwt.sign('_', adminUser, '3650d');
|
const token = await jwt.sign('_', adminUser, '3650d', process.env.NUXT_PUBLIC_DOMAIN_BASE ?? '');
|
||||||
|
|
||||||
await db.close();
|
await db.close();
|
||||||
return token;
|
return token;
|
||||||
|
@ -27,13 +27,14 @@ import jwt from './jwt.ts';
|
|||||||
process.stdin.on('end', () => resolve(data));
|
process.stdin.on('end', () => resolve(data));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const domainBase = process.env.NUXT_PUBLIC_DOMAIN_BASE ?? '';
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
case 'encrypt':
|
case 'encrypt':
|
||||||
console.log(await jwt.sign('_', JSON.parse(input)));
|
console.log(await jwt.sign('_', JSON.parse(input), '365d', domainBase));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'decrypt':
|
case 'decrypt':
|
||||||
console.log(JSON.stringify(await jwt.validate('_', input), null, 2));
|
console.log(JSON.stringify(await jwt.validate('_', input, domainBase), null, 2));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -21,17 +21,26 @@ class Jwt {
|
|||||||
return new Jwt(privateKey, publicKey);
|
return new Jwt(privateKey, publicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
async sign(locale: string, payload: JWTPayload, expiresIn = '365d'): Promise<string> {
|
async sign(
|
||||||
|
locale: string,
|
||||||
|
payload: JWTPayload,
|
||||||
|
expiresIn = '365d',
|
||||||
|
domainBase: string | undefined = undefined,
|
||||||
|
): Promise<string> {
|
||||||
return await new SignJWT(payload)
|
return await new SignJWT(payload)
|
||||||
.setProtectedHeader({ alg: 'RS256' })
|
.setProtectedHeader({ alg: 'RS256' })
|
||||||
.setExpirationTime(expiresIn)
|
.setExpirationTime(expiresIn)
|
||||||
.setAudience(getUrlsForAllLocales(locale))
|
.setAudience(getUrlsForAllLocales(locale, false, domainBase))
|
||||||
.setIssuer(getUrlForLocale(locale))
|
.setIssuer(getUrlForLocale(locale, domainBase))
|
||||||
.sign(this.privateKey);
|
.sign(this.privateKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
async validate<PayloadType = JWTPayload>(locale: string, token: string): Promise<PayloadType | undefined> {
|
async validate<PayloadType = JWTPayload>(
|
||||||
const urls = getUrlsForAllLocales(locale);
|
locale: string,
|
||||||
|
token: string,
|
||||||
|
domainBase: string | undefined = undefined,
|
||||||
|
): Promise<PayloadType | undefined> {
|
||||||
|
const urls = getUrlsForAllLocales(locale, false, domainBase);
|
||||||
try {
|
try {
|
||||||
const { payload } = await jwtVerify<PayloadType>(token, this.publicKey, {
|
const { payload } = await jwtVerify<PayloadType>(token, this.publicKey, {
|
||||||
algorithms: ['RS256'],
|
algorithms: ['RS256'],
|
||||||
|
@ -22,13 +22,17 @@ export const getLocaleUrls = (domainBase: string | undefined): Record<string, st
|
|||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getUrlForLocale = (locale: string) => {
|
export const getUrlForLocale = (locale: string, domainBase: string | undefined = undefined) => {
|
||||||
return getLocaleUrls(useRuntimeConfig().public.domainBase)[locale];
|
return getLocaleUrls(domainBase ?? useRuntimeConfig().public.domainBase)[locale];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getUrlsForAllLocales = (locale: string, includeUnpublished: boolean = false) => {
|
export const getUrlsForAllLocales = (
|
||||||
|
locale: string,
|
||||||
|
includeUnpublished: boolean = false,
|
||||||
|
domainBase: string | undefined = undefined,
|
||||||
|
) => {
|
||||||
const locales = buildLocaleList(locale, includeUnpublished);
|
const locales = buildLocaleList(locale, includeUnpublished);
|
||||||
const urls = getLocaleUrls(useRuntimeConfig().public.domainBase);
|
const urls = getLocaleUrls(domainBase ?? useRuntimeConfig().public.domainBase);
|
||||||
|
|
||||||
const codes = ['_', ...Object.values(locales).map((localeDescription) => localeDescription.code)];
|
const codes = ['_', ...Object.values(locales).map((localeDescription) => localeDescription.code)];
|
||||||
return codes.map((code) => urls[code]);
|
return codes.map((code) => urls[code]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user