Commit 53cb6d9d authored by Guillermo Sanz López's avatar Guillermo Sanz López
Browse files

changes after demos

parent 0c4d913d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
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_GRAFANA_BASE_URL="https://10.95.82.71:3000"
#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
+13 −1
Original line number Diff line number Diff line
@@ -7,6 +7,18 @@ export const getInvokers = async () => {
  return axiosInstance.get(`/resources/invokers`)
}

export const getNumInvokers = async () => {
  return axiosInstance.get(`/resources/numInvokers`)
}

export const getNumProviders = async () => {
  return axiosInstance.get(`/resources/numProviders`)
}

export const getNumUsers1 = async () => {
  return axiosInstance.get(`/resources/numUsers`)
}

export const getInvokerSecurity = async invokerId => {
  return axiosInstance.get(`/resources/invokers/security/${invokerId}`)
}
@@ -24,7 +36,7 @@ export const getEvents = async id => {
}

export const getUsers = async id => {
  return axiosInstance1.get(`/users`)
  return axiosInstance.get(`/users`)
}

export const getUser = async id => {
+2 −1
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ const REFRESH_TOKEN_ENCRYPTION_KEY = 'cS03zO8tdItqbaUyxR3ze48rYol6ugZo'
const USER_DATA_KEY = 'zkUNZjN6yRMKyfdJBfRp'
const USER_DATA_ENCRYPTION_KEY = 'NxAQ5DFsGn7wRTyxEjwawSgUEdsUVknx'

// get the token from the cookies and set in the axios instance
export const setAccessToken = accessToken => {
  Cookies.set(ACCESS_TOKEN_KEY, encryptString(accessToken, ACCESS_TOKEN_ENCRYPTION_KEY), {
    secure: true,
@@ -15,7 +16,7 @@ export const setAccessToken = accessToken => {
  })
}

// getAccessToken() se utiliza para obtener el token de acceso almacenado en las cookies
// getAccessToken() se utiliza para obtener el token de acceso almacenado en las cookies o null si no existe
export const getAccessToken = () => {
  return Cookies.get(ACCESS_TOKEN_KEY) // comprueba si la cookie existe
    ? decryptString(Cookies.get(ACCESS_TOKEN_KEY), ACCESS_TOKEN_ENCRYPTION_KEY) // si existe, desencripta el token de acceso uitlizando la clave de cifrado
+10 −19
Original line number Diff line number Diff line
@@ -40,12 +40,17 @@ const AuthProvider = ({ children }) => {
  // useRouter() -> hook de next que nos permite acceder a la ruta actual
  const router = useRouter()

  // useEffect -> hook de react que se ejecuta cuando el componente se monta, 1 VEZ
  useEffect(() => {
    const initAuth = async () => {
      const storedAccessToken = getAccessToken()
      console.log(storedAccessToken)

      if (storedAccessToken) {
        setLoading(true)
        try {
          // https://10.95.82.71:8085/auth/me + Authorization: Bearer token
          
          const response = await axiosInstance.get(authConfig.meEndpoint, {
            headers: {
              Authorization: `Bearer ${storedAccessToken}`
@@ -53,7 +58,9 @@ const AuthProvider = ({ children }) => {
          })
          setUser(getUserData())
          setLoading(false)
        } catch (error) {
        
        // SI EL TOKEN FALLA, 
        } catch (error) { // EN CASO DE ERROR
          try {
            const response = await axiosInstance.post(authConfig.refreshEndpoint)
            setAccessToken(response.data.access_token)
@@ -77,23 +84,7 @@ const AuthProvider = ({ children }) => {
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])

  // const handleLogin = (params, errorCallback) => {
  //   axiosInstance
  //     .post(authConfig.loginEndpoint, params)
  //     .then(async response => {
  //       params.rememberMe
  //         ? window.localStorage.setItem(authConfig.storageTokenKeyName, response.data.accessToken)
  //         : null
  //       const returnUrl = router.query.returnUrl
  //       setUser({ ...response.data.userData })
  //       params.rememberMe ? window.localStorage.setItem('userData', JSON.stringify(response.data.userData)) : null
  //       const redirectURL = returnUrl && returnUrl !== '/' ? returnUrl : '/'
  //       router.replace(redirectURL)
  //     })
  //     .catch(err => {
  //       if (errorCallback) errorCallback(err)
  //     })
  // }

  const handleLogin = async (params, errorCallback) => {
    try {
      const formData = new FormData()
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
 */
const getHomeRoute = role => {
  if (role === 'client') return '/acl'
  else return '/dashboard'
  else return '/home-dashboards'
}

export default getHomeRoute
Loading