Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
eliobischof authored Dec 5, 2024
2 parents 16902a0 + 7f22c05 commit ad1731d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
16 changes: 13 additions & 3 deletions apps/login/src/components/login-otp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function LoginOTP({
value: host
? {
urlTemplate:
`${host.includes("localhost") ? "http://" : "https://"}${host}/otp/method=${method}?code={{.Code}}&userId={{.UserID}}&sessionId={{.SessionID}}&organization={{.OrgID}}` +
`${host.includes("localhost") ? "http://" : "https://"}${host}/otp/method=${method}?code={{.Code}}&userId={{.UserID}}&sessionId={{.SessionID}}` +
(authRequestId ? `&authRequestId=${authRequestId}` : ""),
}
: {},
Expand All @@ -107,14 +107,19 @@ export function LoginOTP({
challenges,
authRequestId,
})
.catch((error) => {
setError(error.message ?? "Could not request OTP challenge");
.catch(() => {
setError("Could not request OTP challenge");
return;
})
.finally(() => {
setLoading(false);
});

if (response && "error" in response && response.error) {
setError(response.error);
return;
}

return response;
}

Expand Down Expand Up @@ -167,6 +172,11 @@ export function LoginOTP({
setLoading(false);
});

if (response && "error" in response && response.error) {
setError(response.error);
return;
}

return response;
}

Expand Down
10 changes: 10 additions & 0 deletions apps/login/src/components/login-passkey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ export function LoginPasskey({
setLoading(false);
});

if (session && "error" in session && session.error) {
setError(session.error);
return;
}

return session;
}

Expand All @@ -132,6 +137,11 @@ export function LoginPasskey({
setLoading(false);
});

if (response && "error" in response && response.error) {
setError(response.error);
return;
}

return response;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/login/src/lib/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export async function removeSessionFromCookie<T>(
}
}

export async function getMostRecentSessionCookie<T>(): Promise<any> {
export async function getMostRecentSessionCookie<T>(): Promise<Cookie> {
const cookiesList = await cookies();
const stringifiedCookie = cookiesList.get("sessions");

Expand Down
28 changes: 17 additions & 11 deletions apps/login/src/lib/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,23 @@ export async function updateSession(options: UpdateSessionCommand) {
challenges,
} = options;
const recentSession = sessionId
? await getSessionCookieById({ sessionId }).catch((error) => {
return Promise.reject(error);
})
? await getSessionCookieById({ sessionId })
: loginName
? await getSessionCookieByLoginName({ loginName, organization }).catch(
(error) => {
return Promise.reject(error);
},
)
: await getMostRecentSessionCookie().catch((error) => {
return Promise.reject(error);
});
? await getSessionCookieByLoginName({ loginName, organization })
: await getMostRecentSessionCookie();

if (!recentSession) {
return {
error: "Could not find session",
};
}

const host = (await headers()).get("host");

if (!host) {
return { error: "Could not get host" };
}

if (
host &&
challenges &&
Expand Down Expand Up @@ -174,6 +176,10 @@ export async function updateSession(options: UpdateSessionCommand) {
lifetime,
);

if (!session) {
return { error: "Could not update session" };
}

// if password, check if user has MFA methods
let authMethods;
if (checks && checks.password && session.factors?.user?.id) {
Expand Down

0 comments on commit ad1731d

Please sign in to comment.