|
@ -1,27 +1,23 @@ |
|
|
import { Button, Divider, Flex, useToast } from "@chakra-ui/react"; |
|
|
|
|
|
import axios from "axios"; |
|
|
|
|
|
import { useEffect, useState } from "react"; |
|
|
|
|
|
import QrReader from "react-qr-reader"; |
|
|
|
|
|
import { useDispatch, useSelector } from "react-redux"; |
|
|
|
|
|
import { Redirect, useHistory } from "react-router-dom"; |
|
|
|
|
|
import { authLogout } from "../features/auth/authSlice"; |
|
|
|
|
|
|
|
|
import { Button, Divider, Flex, useToast } from '@chakra-ui/react'; |
|
|
|
|
|
import axios from 'axios'; |
|
|
|
|
|
import { useEffect, useState } from 'react'; |
|
|
|
|
|
import QrReader from 'react-qr-reader'; |
|
|
|
|
|
import { useDispatch, useSelector } from 'react-redux'; |
|
|
|
|
|
import { Redirect, useHistory } from 'react-router-dom'; |
|
|
|
|
|
import { authLogout } from '../features/auth/authSlice'; |
|
|
|
|
|
|
|
|
function Scanner() { |
|
|
function Scanner() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const toast = useToast(); |
|
|
const toast = useToast(); |
|
|
const history = useHistory(); |
|
|
const history = useHistory(); |
|
|
const dispatch = useDispatch(); |
|
|
const dispatch = useDispatch(); |
|
|
|
|
|
|
|
|
const [scanData, setScanData] = useState(null); |
|
|
const [scanData, setScanData] = useState(null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleError = (err) => { |
|
|
|
|
|
|
|
|
const handleError = err => { |
|
|
console.log(err); |
|
|
console.log(err); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const handleScan = (res) => { |
|
|
|
|
|
|
|
|
const handleScan = res => { |
|
|
if (res && res !== scanData) { |
|
|
if (res && res !== scanData) { |
|
|
setScanData(res); |
|
|
setScanData(res); |
|
|
} |
|
|
} |
|
@ -34,13 +30,15 @@ function Scanner() { |
|
|
const re = /verify\/.*$/; |
|
|
const re = /verify\/.*$/; |
|
|
const hash = re.exec(scanData); |
|
|
const hash = re.exec(scanData); |
|
|
if (hash) { |
|
|
if (hash) { |
|
|
axios.post(`${process.env.REACT_APP_API_URL}/verify`, |
|
|
|
|
|
|
|
|
axios |
|
|
|
|
|
.post( |
|
|
|
|
|
`${process.env.REACT_APP_API_URL}/verify`, |
|
|
{ |
|
|
{ |
|
|
id: hash[0].substr(7), |
|
|
id: hash[0].substr(7), |
|
|
}, |
|
|
}, |
|
|
{ withCredentials: true }) |
|
|
|
|
|
.then((res) => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ withCredentials: true } |
|
|
|
|
|
) |
|
|
|
|
|
.then(res => { |
|
|
if (res.data.success) { |
|
|
if (res.data.success) { |
|
|
if (res.data.loggedIn) { |
|
|
if (res.data.loggedIn) { |
|
|
toast({ |
|
|
toast({ |
|
@ -49,13 +47,13 @@ function Scanner() { |
|
|
duration: 2000, |
|
|
duration: 2000, |
|
|
}); |
|
|
}); |
|
|
} else { |
|
|
} else { |
|
|
console.log("Time to logout!"); |
|
|
|
|
|
|
|
|
console.log('Time to logout!'); |
|
|
dispatch(authLogout()); |
|
|
dispatch(authLogout()); |
|
|
history.push("/login"); |
|
|
|
|
|
|
|
|
history.push('/login'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
.catch((e) => { |
|
|
|
|
|
|
|
|
.catch(e => { |
|
|
toast({ |
|
|
toast({ |
|
|
title: 'Bad Verification', |
|
|
title: 'Bad Verification', |
|
|
status: 'error', |
|
|
status: 'error', |
|
@ -86,7 +84,13 @@ function Scanner() { |
|
|
facingMode="environment" |
|
|
facingMode="environment" |
|
|
/> |
|
|
/> |
|
|
<Divider mb={6} /> |
|
|
<Divider mb={6} /> |
|
|
<Button onClick={() => { history.push("/home"); }}>Show my QR Code</Button> |
|
|
|
|
|
|
|
|
<Button |
|
|
|
|
|
onClick={() => { |
|
|
|
|
|
history.push('/home'); |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
Show my QR Code |
|
|
|
|
|
</Button> |
|
|
</Flex> |
|
|
</Flex> |
|
|
</Flex> |
|
|
</Flex> |
|
|
); |
|
|
); |
|
|