Skip to content

Commit

Permalink
Merge pull request #114 from sena-proyectos/prod-version
Browse files Browse the repository at this point in the history
fix: error in public token access and coordination registers
  • Loading branch information
lorenqg authored Nov 7, 2023
2 parents e4ec205 + 3baeb39 commit d4d3b6e
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 11 deletions.
11 changes: 10 additions & 1 deletion client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,29 @@ import { TeacherClass } from './components/Teacher-class/TeacherClass'
import { InfoStudent } from './components/Info-student/InfoStudent'
import { RegisterUser } from './components/Register-user/RegisterUser'
import { getPublicToken } from './api/httpRequest'
import { useEffect } from 'react'
import { useEffect, useState } from 'react'
import { getPublicTokenFromSession } from './import/getPublicToken'

const App = () => {
const [loading, setLoading] = useState(true)

useEffect(() => {
const publicToken = getPublicTokenFromSession()
if (!publicToken) {
getAndSavePublicToken()
} else {
setLoading(false)
}
}, [])

const getAndSavePublicToken = async () => {
const response = await getPublicToken()
sessionStorage.setItem('public-token', response)
setLoading(false)
}

if (loading) {
return <div>Terminando de configurar algunos ajustes...</div>
}

return (
Expand Down
4 changes: 3 additions & 1 deletion client/src/ProtectedRoute.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Cookies from 'js-cookie'
import { isExpired } from 'react-jwt'
import { Navigate, useLocation } from 'react-router-dom'
import { getPublicTokenFromSession } from './import/getPublicToken'

export const ProtectedRoute = ({ redirectTo, children }) => {
const location = useLocation()
Expand All @@ -22,7 +23,8 @@ export const IsLogged = ({ redirectTo, children }) => {
const idRol = localStorage.getItem('idRol')
const token = Cookies.get('token')

const publicToken = sessionStorage.getItem('public-token')
const publicToken = getPublicTokenFromSession()

const isExpiredToken = token ? isExpired(token) : true
const isExpiredPublicToken = publicToken ? isExpired(publicToken) : true

Expand Down
Loading

0 comments on commit d4d3b6e

Please sign in to comment.