priviligies
This commit is contained in:
parent
0ecdc6db20
commit
f319e022fe
@ -1,6 +1,7 @@
|
|||||||
import React, { useState, useEffect, createContext, ReactNode } from 'react';
|
import React, { useState, useEffect, createContext, ReactNode } from 'react';
|
||||||
import { LoggedUser } from '../types';
|
import { LoggedUser } from '../types';
|
||||||
import { axiosInstance } from '../utils/axiosInstance';
|
import { axiosInstance, getNewTokens } from '../utils/axiosInstance';
|
||||||
|
|
||||||
|
|
||||||
export interface CASContext {
|
export interface CASContext {
|
||||||
user: LoggedUser | undefined;
|
user: LoggedUser | undefined;
|
||||||
@ -42,6 +43,9 @@ export const CASProvider = ({ children }: CASProviderProps) => {
|
|||||||
localStorage.setItem('refreshToken', user.refreshToken);
|
localStorage.setItem('refreshToken', user.refreshToken);
|
||||||
setIsFetchingToken(false);
|
setIsFetchingToken(false);
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
getNewTokens();
|
||||||
|
}
|
||||||
const token = localStorage.getItem('userToken');
|
const token = localStorage.getItem('userToken');
|
||||||
const refreshToken = localStorage.getItem('refreshToken');
|
const refreshToken = localStorage.getItem('refreshToken');
|
||||||
const role = localStorage.getItem('userPrivilige');
|
const role = localStorage.getItem('userPrivilige');
|
||||||
|
@ -3,12 +3,14 @@ import axios from 'axios';
|
|||||||
export const axiosInstance = axios.create();
|
export const axiosInstance = axios.create();
|
||||||
|
|
||||||
//getting new tokens
|
//getting new tokens
|
||||||
const getNewTokens = async () => {
|
export const getNewTokens = async () => {
|
||||||
try {
|
try {
|
||||||
const refreshToken = localStorage.getItem('refreshToken');
|
const refreshToken = localStorage.getItem('refreshToken');
|
||||||
const { data } = await axiosInstance.get(
|
const { data } = await axiosInstance.get(
|
||||||
`${process.env.REACT_APP_API_URL}/token/refresh?refreshToken=${refreshToken}`,
|
`${process.env.REACT_APP_API_URL}/token/refresh?refreshToken=${refreshToken}`,
|
||||||
);
|
);
|
||||||
|
console.log("12312321",data);
|
||||||
|
localStorage.setItem('userPrivilige',data.authorityRole);
|
||||||
localStorage.setItem('userToken', data.token);
|
localStorage.setItem('userToken', data.token);
|
||||||
localStorage.setItem('refreshToken', data.refreshToken);
|
localStorage.setItem('refreshToken', data.refreshToken);
|
||||||
return data.token;
|
return data.token;
|
||||||
|
Loading…
Reference in New Issue
Block a user