Advertisement
Piotoru

check token

Feb 27th, 2023
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. export default function VerifyEmail() {
  2. const [status, setStatus] = useState<'success' | 'error' | ''>('');
  3. const [valuesFields, setValuesFields] = useState<string>('');
  4.  
  5. const sendEmail = async () => {
  6. try {
  7. const response = await sendVerificationEmail();
  8. if (response.status === 'OK') {
  9. setValuesFields('Please check your email and click the link in it');
  10. }
  11. } catch (e: any) {
  12. setValuesFields(e.isSuperTokensGeneralError === true ? e.message :'Oops! Something went wrong.');
  13. }
  14. };
  15.  
  16. const consumeVerificationCode = async () => {
  17. try {
  18. const response = await verifyEmail();
  19. if (response.status === 'EMAIL_VERIFICATION_INVALID_TOKEN_ERROR') {
  20. setValuesFields('The verification code is expired or invalid. Please click the button to send new email verification link again.');
  21. setStatus('error');
  22. } else {
  23. setValuesFields('You verified your e-mail.');
  24. setStatus('success');
  25. }
  26. } catch (e: any) {
  27. setValuesFields(e.isSuperTokensGeneralError === true ? e.message :'Oops! Something went wrong.');
  28. }
  29. };
  30.  
  31. useEffect(() => {
  32. consumeVerificationCode();
  33. }, []);
  34.  
  35. if (status === '') {
  36. return null;
  37. }
  38.  
  39. return (
  40. <>
  41. <div className={styles.container}>
  42. <Image
  43. src={status === 'success' ? success : error}
  44. objectFit="contain"
  45. objectPosition="center"
  46. width="200"
  47. height="200"
  48. alt={`${status === 'success' ? 'success' : 'error'} icon`}
  49. priority
  50. />
  51. {status === 'success' ? (
  52. <>
  53. <h2>Congratulations!</h2>
  54. <p>{valuesFields}</p>
  55. </>
  56. ) : (
  57. <>
  58. <p>{valuesFields}</p>
  59. <Button colorScheme="blue" borderColor="transparent" onClick={sendEmail}>
  60. Continue
  61. </Button>
  62. </>
  63. )}
  64. </div>
  65. <Footer />
  66. </>
  67. );
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement