mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-14 09:52:12 +00:00
otp setup docs
This commit is contained in:
@@ -31,8 +31,7 @@ export default async function Page({
|
||||
organization,
|
||||
});
|
||||
|
||||
let totpResponse: RegisterTOTPResponse | undefined,
|
||||
totpError: Error | undefined;
|
||||
let totpResponse: RegisterTOTPResponse | undefined, error: Error | undefined;
|
||||
if (session && session.factors?.user?.id) {
|
||||
if (method === "time-based") {
|
||||
await registerTOTP(session.factors.user.id)
|
||||
@@ -41,15 +40,21 @@ export default async function Page({
|
||||
totpResponse = resp;
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
totpError = error;
|
||||
.catch((err) => {
|
||||
error = err;
|
||||
});
|
||||
} else if (method === "sms") {
|
||||
// does not work
|
||||
await addOTPSMS(session.factors.user.id);
|
||||
await addOTPSMS(session.factors.user.id).catch((error) => {
|
||||
console.error(error);
|
||||
error = new Error("Could not add OTP via SMS");
|
||||
});
|
||||
} else if (method === "email") {
|
||||
// works
|
||||
await addOTPEmail(session.factors.user.id);
|
||||
await addOTPEmail(session.factors.user.id).catch((error) => {
|
||||
console.error(error);
|
||||
error = new Error("Could not add OTP via Email");
|
||||
});
|
||||
} else {
|
||||
throw new Error("Invalid method");
|
||||
}
|
||||
@@ -98,9 +103,9 @@ export default async function Page({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{totpError && (
|
||||
{error && (
|
||||
<div className="py-4">
|
||||
<Alert>{totpError?.message}</Alert>
|
||||
<Alert>{error?.message}</Alert>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -119,8 +124,6 @@ export default async function Page({
|
||||
Scan the QR Code or navigate to the URL manually.
|
||||
</p>
|
||||
<div>
|
||||
{/* {auth && <div>{auth.to}</div>} */}
|
||||
|
||||
<TOTPRegister
|
||||
uri={totpResponse.uri as string}
|
||||
secret={totpResponse.secret as string}
|
||||
|
||||
@@ -74,39 +74,11 @@ export async function addOTPEmail(userId: string) {
|
||||
);
|
||||
}
|
||||
|
||||
export async function addOTPSMS(userId: string, token?: string) {
|
||||
// TODO: Follow up here, I do not understand the branching
|
||||
// let userService;
|
||||
// if (token) {
|
||||
// const authConfig: ZitadelServerOptions = {
|
||||
// name: "zitadel login",
|
||||
// apiUrl: process.env.ZITADEL_API_URL ?? "",
|
||||
// token: token,
|
||||
// };
|
||||
// const sessionUser = initializeServer(authConfig);
|
||||
// userService = user.getUser(sessionUser);
|
||||
// } else {
|
||||
// userService = user.getUser(server);
|
||||
// }
|
||||
|
||||
export async function addOTPSMS(userId: string) {
|
||||
return userService.addOTPSMS({ userId }, {});
|
||||
}
|
||||
|
||||
export async function registerTOTP(userId: string, token?: string) {
|
||||
// TODO: Follow up here, I do not understand the branching
|
||||
// let userService;
|
||||
// if (token) {
|
||||
// const authConfig: ZitadelServerOptions = {
|
||||
// name: "zitadel login",
|
||||
// apiUrl: process.env.ZITADEL_API_URL ?? "",
|
||||
// token: token,
|
||||
// };
|
||||
//
|
||||
// const sessionUser = initializeServer(authConfig);
|
||||
// userService = user.getUser(sessionUser);
|
||||
// } else {
|
||||
// userService = user.getUser(server);
|
||||
// }
|
||||
export async function registerTOTP(userId: string) {
|
||||
return userService.registerTOTP({ userId }, {});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user