Commit 0c4d913d authored by Guillermo Sanz López's avatar Guillermo Sanz López
Browse files

add comments

parent 24fd71ae
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
NEXT_PUBLIC_API_BASE_URL="http://10.95.82.71:8085"
NEXT_PUBLIC_GRAFANA_BASE_URL="http://10.95.82.71:3000"
NEXT_PUBLIC_API_BASE_URL_V1="http://10.95.235.20:9000"
NEXT_PUBLIC_GRAFANA_BASE_URL_V1="http://10.95.235.20:3001"
NEXT_PUBLIC_API_BASE_URL="https://10.95.82.71:8085"
#NEXT_PUBLIC_API_BASE_URL="http://10.95.235.20:9000"
NEXT_PUBLIC_GRAFANA_BASE_URL="http://10.95.235.20:3001"
NEXT_PUBLIC_JWT_EXPIRATION= 5m
NEXT_PUBLIC_JWT_SECRET= dd5f3089-40c3-403d-af14-d0c228b05cb4
NEXT_PUBLIC_JWT_REFRESH_TOKEN_SECRET= 7c4c1c50-3230-45bf-9eae-c9b2e401c767
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ axiosInstance.interceptors.request.use(
    const accessToken = getAccessToken()
    const refreshToken = getRefreshToken()

    // if token existe and request is not refresh, add token to headers
    // if token exist and request is not refresh, add token to headers
    if (accessToken && req.url !== '/refresh') {
      req.headers['Authorization'] = `Bearer ${accessToken}`
    }
+6 −14
Original line number Diff line number Diff line
@@ -18,7 +18,8 @@ import {
  setUserData
} from 'src/configs/cookies'

// ** Defaults
// ** Defaults -> para compartir el estado de autenticación entre componentes
// los componentes que necesiten acceder al estado de autenticación, importarán AuthContext
const defaultProvider = {
  user: null,
  loading: true,
@@ -29,13 +30,16 @@ const defaultProvider = {
}
const AuthContext = createContext(defaultProvider)

// ** Provider -> componente que envuelve a la aplicación entera
const AuthProvider = ({ children }) => {
  // ** States
  // ** States -> solo local para este componente, useState (por defecto, el usuario es null)
  const [user, setUser] = useState(defaultProvider.user)
  const [loading, setLoading] = useState(defaultProvider.loading)

  // ** Hooks
  // useRouter() -> hook de next que nos permite acceder a la ruta actual
  const router = useRouter()
  
  useEffect(() => {
    const initAuth = async () => {
      const storedAccessToken = getAccessToken()
@@ -69,18 +73,6 @@ const AuthProvider = ({ children }) => {
      }
    }

    // setTimeout(() => {
    //   // MIO, quitar todo y descomentar initAuth
    //   if (window.localStorage.getItem('userData')) {
    //     console.log(JSON.parse(window.localStorage.getItem('userData')))
    //     setUser(JSON.parse(window.localStorage.getItem('userData')))
    //     setLoading(false)
    //   } else {
    //     setUser(null)
    //     setLoading(false)
    //   }
    // }, 1000)

    initAuth()
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])