-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
76 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ export interface User { | |
id: string; | ||
email: string; | ||
username: string; | ||
is_verified: boolean; | ||
} |
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
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,31 @@ | ||
import { useEffect } from "react"; | ||
import { useNavigate, useSearchParams } from "react-router-dom"; | ||
import { verify } from "../api/auth/auth.api"; | ||
import { navigateWithToast } from "../utilities/navigate"; | ||
|
||
export default function VerifyAuth() { | ||
const [searchParams] = useSearchParams(); | ||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
const token = searchParams.get('token'); | ||
|
||
if (token) { | ||
// Perform verification | ||
const result = await verify(token); | ||
if (!result) { | ||
navigateWithToast(navigate, '/login', 'Verified your account. You can login now!', 'success'); | ||
} else { | ||
navigateWithToast(navigate, '/login', `Failed to verify your account because: ${result}`, 'error'); | ||
} | ||
} else { | ||
navigateWithToast(navigate, '/login', 'Invalid auth', 'error'); | ||
} | ||
})(); | ||
}, []) | ||
|
||
return ( | ||
<div>Verifying your token...</div> | ||
) | ||
} |
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,16 @@ | ||
import { ToastMessageType } from "../components/Layout"; | ||
import { NavigateFunction, createSearchParams } from "react-router-dom"; | ||
|
||
export function navigateWithToast( | ||
navigate: NavigateFunction, | ||
to: string, | ||
message: string, | ||
messageType: ToastMessageType) { | ||
navigate({ | ||
pathname: to, | ||
search: createSearchParams({ | ||
'message': message, | ||
'message-type': messageType, | ||
}).toString() | ||
}); | ||
} |