feat(frontend): redirect user to login in case of expired jwt
This commit is contained in:
parent
17306b8923
commit
5db5aa3ab7
|
|
@ -98,6 +98,9 @@ const addDeviceObj = async(obj, setShowLoading, router, updateDeviceParameters)
|
||||||
setShowLoading(true)
|
setShowLoading(true)
|
||||||
let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/add`, requestOptions))
|
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 != 200) {
|
||||||
|
if (result.status === 401){
|
||||||
|
router.push("/auth/login")
|
||||||
|
}
|
||||||
setShowLoading(false)
|
setShowLoading(false)
|
||||||
throw new Error('Please check your email and password');
|
throw new Error('Please check your email and password');
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -130,6 +133,9 @@ const deleteDeviceObj = async(obj, setShowLoading, router, updateDeviceParameter
|
||||||
setShowLoading(true)
|
setShowLoading(true)
|
||||||
let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/del`, requestOptions))
|
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 != 200) {
|
||||||
|
if (result.status === 401){
|
||||||
|
router.push("/auth/login")
|
||||||
|
}
|
||||||
setShowLoading(false)
|
setShowLoading(false)
|
||||||
throw new Error('Please check your email and password');
|
throw new Error('Please check your email and password');
|
||||||
}else{
|
}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))
|
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 != 200) {
|
||||||
|
if (result.status === 401){
|
||||||
|
router.push("/auth/login")
|
||||||
|
}
|
||||||
throw new Error('Please check your email and password');
|
throw new Error('Please check your email and password');
|
||||||
}else if (result.status === 401){
|
}else if (result.status === 401){
|
||||||
router.push("/auth/login")
|
router.push("/auth/login")
|
||||||
|
|
@ -1021,6 +1030,9 @@ const getDeviceParameterInstances = async (raw) =>{
|
||||||
setShowLoading(true)
|
setShowLoading(true)
|
||||||
let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/set`, requestOptions))
|
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 != 200) {
|
||||||
|
if (result.status === 401){
|
||||||
|
router.push("/auth/login")
|
||||||
|
}
|
||||||
setShowLoading(false)
|
setShowLoading(false)
|
||||||
throw new Error('Please check your email and password');
|
throw new Error('Please check your email and password');
|
||||||
}else{
|
}else{
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,9 @@ const handleOpen = () => {
|
||||||
fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/${method}`, requestOptions)
|
fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/${method}`, requestOptions)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(result => {
|
.then(result => {
|
||||||
|
if (result.status === 401){
|
||||||
|
router.push("/auth/login")
|
||||||
|
}
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
setAnswer(true)
|
setAnswer(true)
|
||||||
let teste = JSON.stringify(JSON.parse(result), null, 2)
|
let teste = JSON.stringify(JSON.parse(result), null, 2)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user