-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add email confirmation workflow (#651)
* Backend work * Frontend email verification * lint fixes * Backend tests
- Loading branch information
Showing
14 changed files
with
422 additions
and
5 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
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,64 @@ | ||
import React from "react" | ||
import { GraphQLError } from "graphql" | ||
import { render, screen, waitFor } from "testing" | ||
import VerifyEmail, { VERIFY_EMAIL } from "./VerifyEmail" | ||
|
||
test("renders", async () => { | ||
render(<VerifyEmail />, { | ||
route: "/email-verification?token=abc&uid=1234", | ||
path: "email-verification", | ||
routes: ["/"], | ||
}) | ||
|
||
expect(screen.getByRole("progressbar")).toBeTruthy() | ||
|
||
await screen.findByText("New Page") | ||
}) | ||
|
||
test("missing token", async () => { | ||
render(<VerifyEmail />, { | ||
route: "/email-verification?uid=1234", | ||
path: "email-verification", | ||
routes: ["/"], | ||
}) | ||
|
||
await screen.findByText("Missing required token") | ||
}) | ||
|
||
test("missing uid", async () => { | ||
render(<VerifyEmail />, { | ||
route: "/email-verification?token=abc", | ||
path: "email-verification", | ||
routes: ["/"], | ||
}) | ||
|
||
await screen.findByText("Missing required token") | ||
}) | ||
|
||
test("error", async () => { | ||
const mocks = [ | ||
{ | ||
request: { | ||
query: VERIFY_EMAIL, | ||
variables: { | ||
uid: "1234", | ||
token: "abc", | ||
}, | ||
}, | ||
result: { | ||
errors: [new GraphQLError("Error!")], | ||
}, | ||
}, | ||
] | ||
|
||
render(<VerifyEmail />, { | ||
route: "/email-verification?token=abc&uid=1234", | ||
path: "email-verification", | ||
routes: ["/"], | ||
mocks, | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText("Error!")).toBeInTheDocument() | ||
}) | ||
}) |
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,52 @@ | ||
import React, { useEffect } from "react" | ||
import { gql, useMutation } from "@apollo/client" | ||
import { useSnackbar } from "notistack" | ||
import { useNavigate, useSearchParams } from "react-router-dom" | ||
import Loading from "components/layout/Loading" | ||
import GraphError from "components/utils/GraphError" | ||
import { Verify, VerifyVariables } from "./__generated__/Verify" | ||
|
||
export const VERIFY_EMAIL = gql` | ||
mutation Verify($uid: String!, $token: String!) { | ||
verifyEmail(uid: $uid, token: $token) { | ||
id | ||
} | ||
} | ||
` | ||
|
||
const VerifyEmail: React.FC = () => { | ||
const [searchParams] = useSearchParams() | ||
const navigate = useNavigate() | ||
const { enqueueSnackbar } = useSnackbar() | ||
|
||
const [verifyEmail, { error }] = useMutation<Verify, VerifyVariables>( | ||
VERIFY_EMAIL, | ||
) | ||
|
||
const uid = searchParams.get("uid") | ||
const token = searchParams.get("token") | ||
|
||
useEffect(() => { | ||
if (!uid || !token) return | ||
|
||
verifyEmail({ | ||
variables: { | ||
uid, | ||
token, | ||
}, | ||
}) | ||
.then(() => enqueueSnackbar("Email verified", { variant: "success" })) | ||
.then(() => { | ||
navigate("/") | ||
}) | ||
.catch(() => {}) | ||
}, [uid, token, verifyEmail, navigate, enqueueSnackbar]) | ||
|
||
if (error) return <GraphError error={error} /> | ||
|
||
if (!uid || !token) return <>Missing required token</> | ||
|
||
return <Loading /> | ||
} | ||
|
||
export default VerifyEmail |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.