session, login prompt, select account to callback

This commit is contained in:
peintnermax
2024-03-06 13:35:21 +01:00
parent 503783fbf3
commit 9e0d9d6c46
2 changed files with 45 additions and 3 deletions

View File

@@ -38,10 +38,25 @@ function findSession(
export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams;
const authRequestId = searchParams.get("authRequest");
const sessionId = searchParams.get("sessionId");
const sessionCookies: SessionCookie[] = await getAllSessions();
if (authRequestId && sessionId) {
const cookie = sessionCookies.find((cookie) => cookie.id === sessionId);
const session = {
sessionId: cookie?.id,
sessionToken: cookie?.token,
};
const { callbackUrl } = await createCallback(server, {
authRequestId,
session,
});
return NextResponse.redirect(callbackUrl);
}
if (authRequestId) {
const { authRequest } = await getAuthRequest(server, { authRequestId });
const sessionCookies: SessionCookie[] = await getAllSessions();
const ids = sessionCookies.map((s) => s.id);
let sessions: Session[] = [];
@@ -57,7 +72,8 @@ export async function GET(request: NextRequest) {
// if some accounts are available for selection and select_account is set
if (
authRequest &&
authRequest.prompt.includes(Prompt.PROMPT_SELECT_ACCOUNT)
(authRequest.prompt.includes(Prompt.PROMPT_SELECT_ACCOUNT) ||
authRequest.prompt.includes(Prompt.PROMPT_LOGIN))
) {
const accountsUrl = new URL("/accounts", request.url);
if (authRequest?.id) {

View File

@@ -40,6 +40,32 @@ export default function SessionItem({
}
}
// async function loginSession(authRequestId: string, sessionId: string) {
// setLoading(true);
// const res = await fetch(
// "/api/login?" + new URLSearchParams({ sessionId, authRequestId }),
// {
// method: "DELETE",
// headers: {
// "Content-Type": "application/json",
// },
// body: JSON.stringify({
// id: id,
// }),
// }
// );
// const response = await res.json();
// setLoading(false);
// if (!res.ok) {
// // setError(response.details);
// return Promise.reject(response);
// } else {
// return response;
// }
// }
const validPassword = session?.factors?.password?.verifiedAt;
const validPasskey = session?.factors?.webAuthN?.verifiedAt;
@@ -49,7 +75,7 @@ export default function SessionItem({
<Link
href={
validUser
? `/signedin?` +
? `/login?` +
new URLSearchParams(
authRequestId
? {