feat(frontend): redirect user to login in case of expired jwt

This commit is contained in:
leandrofars 2024-02-22 08:53:59 -03:00
parent 17306b8923
commit 5db5aa3ab7
2 changed files with 15 additions and 0 deletions

View File

@ -98,6 +98,9 @@ const addDeviceObj = async(obj, setShowLoading, router, updateDeviceParameters)
setShowLoading(true)
let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/add`, requestOptions))
if (result.status != 200) {
if (result.status === 401){
router.push("/auth/login")
}
setShowLoading(false)
throw new Error('Please check your email and password');
}else{
@ -130,6 +133,9 @@ const deleteDeviceObj = async(obj, setShowLoading, router, updateDeviceParameter
setShowLoading(true)
let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/del`, requestOptions))
if (result.status != 200) {
if (result.status === 401){
router.push("/auth/login")
}
setShowLoading(false)
throw new Error('Please check your email and password');
}else{
@ -774,6 +780,9 @@ const getDeviceParameterInstances = async (raw) =>{
let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/get`, requestOptions))
if (result.status != 200) {
if (result.status === 401){
router.push("/auth/login")
}
throw new Error('Please check your email and password');
}else if (result.status === 401){
router.push("/auth/login")
@ -1021,6 +1030,9 @@ const getDeviceParameterInstances = async (raw) =>{
setShowLoading(true)
let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/set`, requestOptions))
if (result.status != 200) {
if (result.status === 401){
router.push("/auth/login")
}
setShowLoading(false)
throw new Error('Please check your email and password');
}else{

View File

@ -87,6 +87,9 @@ const handleOpen = () => {
fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/${method}`, requestOptions)
.then(response => response.text())
.then(result => {
if (result.status === 401){
router.push("/auth/login")
}
setOpen(false)
setAnswer(true)
let teste = JSON.stringify(JSON.parse(result), null, 2)