source: frontend/src/Auth/Confirm.js@ 63f5ced

Last change on this file since 63f5ced was a26f6a1, checked in by Danilo <danilo.najkov@…>, 2 years ago

full auth flow

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[a26f6a1]1import React, {useEffect, useState} from 'react'
2import {Header} from "../Header";
3import {Modal, notification, Spin} from "antd";
4import {useLocation} from "react-router";
5import {useNavigate, useSearchParams} from "react-router-dom";
6import axios from "axios";
7import env from "../env";
8
9const Confirm = ({setUser, user}) => {
10
11 const history = useNavigate()
12 const [result, setResult] = useState("")
13 const [searchParams, setSearchParams] = useSearchParams();
14
15 useEffect(()=>{
16 const param = searchParams.get("id");
17 if(param==null){
18 setResult("Invalid key");
19 return;
20 }
21 axios.post(env.api+"Users/confirmed?validityString="+param,{},{headers:{Authorization:localStorage.getItem('Auth')}}).then(el => {
22 setResult("Успешно потврдена емаил адреса. Ќе бидете редиректирани за 3 секунди")
23 setUser(user => {return {...user,isConfirmed: true}})
24 setTimeout(()=>{
25 history('/login')
26 },3000)
27 }).catch(er=>{
28 if(er.response.data.includes("Invalid check")){
29 setResult("Невалиден линк")
30 }
31 if(er.response.data.includes("Link expired")){
32 setResult("Линкот е стар. Ве молиме обновете го.")
33 }
34 });
35
36 },[])
37
38 return (
39 <div>
40 <Header/>
41 <div style={{textAlign:'center',margin:'50px'}}>
42 {result == "" ? <Spin/> : <h2>{result}</h2>}
43 </div>
44 </div>
45 )
46}
47export default Confirm;
Note: See TracBrowser for help on using the repository browser.