Skip to content

Commit

Permalink
Add Magic Link sign in and sign up flows (#892)
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh authored Mar 6, 2024
1 parent fcf0570 commit 49da181
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/auth-core/src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export type BuiltinOAuthProviderNames =

export const emailPasswordProviderName = "builtin::local_emailpassword";
export const webAuthnProviderName = "builtin::local_webauthn";
export const magicLinkProviderName = "builtin::local_magic_link";
31 changes: 31 additions & 0 deletions packages/auth-core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type BuiltinOAuthProviderNames,
emailPasswordProviderName,
webAuthnProviderName,
magicLinkProviderName,
} from "./consts";
import { requestGET, requestPOST } from "./utils";
import type {
Expand Down Expand Up @@ -172,6 +173,36 @@ export class Auth {
return this.getToken(code, verifier);
}

async signupWithMagicLink(
email: string,
callbackUrl: string,
redirectOnFailure: string,
challenge: string
): Promise<void> {
await this._post("magic-link/register", {
provider: magicLinkProviderName,
challenge,
email,
callback_url: callbackUrl,
redirect_on_failure: redirectOnFailure,
});
}

async signinWithMagicLink(
email: string,
callbackUrl: string,
redirectOnFailure: string,
challenge: string
): Promise<void> {
await this._post("magic-link/email", {
provider: magicLinkProviderName,
challenge,
email,
callback_url: callbackUrl,
redirect_on_failure: redirectOnFailure,
});
}

async resendVerificationEmail(verificationToken: string) {
await this._post("resend-verification-email", {
provider: emailPasswordProviderName,
Expand Down

0 comments on commit 49da181

Please sign in to comment.