-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📝 (auth) Enhance email authentication flow with a redirect page
Closes #1824
- Loading branch information
1 parent
c55655a
commit 7b22e3f
Showing
11 changed files
with
122 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
apps/builder/src/features/auth/components/EmailRedirectPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Seo } from "@/components/Seo"; | ||
import { Button, Heading, Tag, Text, VStack } from "@chakra-ui/react"; | ||
import { useQueryState } from "nuqs"; | ||
import { toast } from "sonner"; | ||
import { createEmailMagicLink } from "../helpers/createEmailMagicLink"; | ||
|
||
export const EmailRedirectPage = () => { | ||
const [redirectPath] = useQueryState("redirectPath"); | ||
const [email] = useQueryState("email"); | ||
const [token] = useQueryState("token"); | ||
|
||
const redirectToMagicLink = () => { | ||
if (!token || !email) { | ||
toast.error("Missing token or email query params"); | ||
return; | ||
} | ||
window.location.assign( | ||
createEmailMagicLink(token, email, redirectPath ?? undefined), | ||
); | ||
}; | ||
|
||
if (!email || !token) return null; | ||
|
||
return ( | ||
<VStack spacing={4} h="100vh" justifyContent="center"> | ||
<Seo title={"Email auth confirmation"} /> | ||
<Heading | ||
onClick={() => { | ||
throw new Error("Sentry is working"); | ||
}} | ||
> | ||
Email authentication | ||
</Heading> | ||
<Text> | ||
You are about to login with <Tag>{email}</Tag> | ||
</Text> | ||
<Button onClick={redirectToMagicLink} colorScheme="blue"> | ||
Continue | ||
</Button> | ||
</VStack> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
apps/builder/src/features/auth/helpers/createEmailMagicLink.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const createEmailMagicLink = ( | ||
token: string, | ||
email: string, | ||
redirectPath?: string, | ||
) => { | ||
const url = new URL(`${window.location.origin}/api/auth/callback/email`); | ||
url.searchParams.set("token", token); | ||
url.searchParams.set("email", email); | ||
url.searchParams.set( | ||
"callbackUrl", | ||
`${window.location.origin}${redirectPath ?? "/typebots"}`, | ||
); | ||
return url.toString(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { EmailRedirectPage } from "@/features/auth/components/EmailRedirectPage"; | ||
|
||
export default function Page() { | ||
return <EmailRedirectPage />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.