Merge pull request #193 from OktopUSP/dev

JWT Expiration Time Increase + Redirect to Login Page at 401 Error | Closes #146
This commit is contained in:
Leandro Antônio Farias Machado 2024-02-22 09:04:55 -03:00 committed by GitHub
commit 370e5740e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View File

@ -25,7 +25,7 @@ type JWTClaim struct {
} }
func GenerateJWT(email string, username string) (tokenString string, err error) { func GenerateJWT(email string, username string) (tokenString string, err error) {
expirationTime := time.Now().Add(4 * time.Hour) expirationTime := time.Now().Add(24 * time.Hour)
claims := &JWTClaim{ claims := &JWTClaim{
username, username,
email, email,

View File

@ -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{

View File

@ -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)