mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 06:52:24 +00:00
25 lines
749 B
TypeScript
25 lines
749 B
TypeScript
"use server";
|
|
|
|
import { getMostRecentCookieWithLoginname } from "#/utils/cookies";
|
|
import { getSession, server, verifyTOTPRegistration } from "./zitadel";
|
|
|
|
export async function verifyTOTP(
|
|
code: string,
|
|
loginName?: string,
|
|
organization?: string
|
|
) {
|
|
return getMostRecentCookieWithLoginname(loginName, organization)
|
|
.then((recent) => {
|
|
return getSession(server, recent.id, recent.token).then((response) => {
|
|
return { session: response?.session, token: recent.token };
|
|
});
|
|
})
|
|
.then(({ session, token }) => {
|
|
if (session?.factors?.user?.id) {
|
|
return verifyTOTPRegistration(code, session.factors.user.id, token);
|
|
} else {
|
|
throw Error("No user id found in session.");
|
|
}
|
|
});
|
|
}
|