feat: add admin accounts and image templates
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { SESSION_COOKIE_NAME, getAuthRuntimeConfig, safeNextPath, shouldUseSecureAuthCookie } from "@/lib/auth/config";
|
||||
import { getAuthRuntimeConfig, safeNextPath } from "@/lib/auth/config";
|
||||
import { createSessionCookieValue } from "@/lib/auth/session";
|
||||
import { jsonError, jsonOk, readJsonBody } from "@/lib/server/api";
|
||||
import { createSessionFromClaims, verifyAuthJwt } from "@/lib/server/auth/jwt";
|
||||
import { prepareAuthPassword } from "@/lib/server/auth/password";
|
||||
import { setSessionCookieValue } from "@/lib/server/auth/session-cookie";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
@@ -54,19 +55,21 @@ export async function POST(request: Request) {
|
||||
});
|
||||
if (!token.access_token) throw new PasswordLoginError("认证中心没有返回 access_token。", 502);
|
||||
const claims = await verifyAuthJwt(token.access_token, config);
|
||||
const session = createSessionFromClaims(claims, config, parseExpiresIn(token.expires_in));
|
||||
const session = createSessionFromClaims(claims, config, parseExpiresIn(token.expires_in), {
|
||||
accessToken: token.access_token,
|
||||
tokenType: token.token_type
|
||||
});
|
||||
const response = jsonOk({
|
||||
ok: true,
|
||||
redirectTo: safeNextPath(body.next),
|
||||
user: session.user
|
||||
});
|
||||
response.cookies.set(SESSION_COOKIE_NAME, await createSessionCookieValue(session, config.sessionSecret), {
|
||||
httpOnly: true,
|
||||
sameSite: "lax",
|
||||
secure: shouldUseSecureAuthCookie(request.url),
|
||||
path: "/",
|
||||
expires: new Date(session.expiresAt * 1000)
|
||||
});
|
||||
setSessionCookieValue(
|
||||
response,
|
||||
request.url,
|
||||
await createSessionCookieValue(session, config.sessionSecret),
|
||||
new Date(session.expiresAt * 1000)
|
||||
);
|
||||
return response;
|
||||
} catch (error) {
|
||||
return jsonError(error, 401);
|
||||
|
||||
Reference in New Issue
Block a user