redirect to login with passkey after register with passkey

This commit is contained in:
peintnermax
2024-04-03 14:35:24 +02:00
parent 836df9ea6b
commit 0a1219b07b
3 changed files with 35 additions and 8 deletions

View File

@@ -3,7 +3,10 @@ import Alert from "#/ui/Alert";
import DynamicTheme from "#/ui/DynamicTheme";
import LoginPasskey from "#/ui/LoginPasskey";
import UserAvatar from "#/ui/UserAvatar";
import { getMostRecentCookieWithLoginname } from "#/utils/cookies";
import {
getMostRecentCookieWithLoginname,
getSessionCookieById,
} from "#/utils/cookies";
const title = "Authenticate with a passkey";
const description =
@@ -14,11 +17,17 @@ export default async function Page({
}: {
searchParams: Record<string | number | symbol, string | undefined>;
}) {
const { loginName, altPassword, authRequestId, organization } = searchParams;
const { loginName, altPassword, authRequestId, organization, sessionId } =
searchParams;
const sessionFactors = await loadSession(loginName, organization);
const sessionFactors = sessionId
? await loadSessionById(sessionId, organization)
: await loadSessionByLoginname(loginName, organization);
async function loadSession(loginName?: string, organization?: string) {
async function loadSessionByLoginname(
loginName?: string,
organization?: string
) {
const recent = await getMostRecentCookieWithLoginname(
loginName,
organization
@@ -30,6 +39,15 @@ export default async function Page({
});
}
async function loadSessionById(sessionId: string, organization?: string) {
const recent = await getSessionCookieById(sessionId, organization);
return getSession(server, recent.id, recent.token).then((response) => {
if (response?.session) {
return response.session;
}
});
}
const branding = await getBrandingSettings(server, organization);
return (