Merge pull request 'priviligies' (#64) from statistics into master

Reviewed-on: http://git.plannaplan.pl/y0rune/frontend/pulls/64
Reviewed-by: filipizydorczyk <filip.izydorczyk@protonmail.com>
This commit is contained in:
filipizydorczyk 2021-01-25 18:36:40 +01:00
commit 62d73fcbe3
2 changed files with 8 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import React, { useState, useEffect, createContext, ReactNode } from 'react';
import { LoggedUser } from '../types';
import { axiosInstance } from '../utils/axiosInstance';
import { axiosInstance, getNewTokens } from '../utils/axiosInstance';
export interface CASContext {
user: LoggedUser | undefined;
@ -42,6 +43,9 @@ export const CASProvider = ({ children }: CASProviderProps) => {
localStorage.setItem('refreshToken', user.refreshToken);
setIsFetchingToken(false);
}
else{
getNewTokens();
}
const token = localStorage.getItem('userToken');
const refreshToken = localStorage.getItem('refreshToken');
const role = localStorage.getItem('userPrivilige');

View File

@ -3,12 +3,14 @@ import axios from 'axios';
export const axiosInstance = axios.create();
//getting new tokens
const getNewTokens = async () => {
export const getNewTokens = async () => {
try {
const refreshToken = localStorage.getItem('refreshToken');
const { data } = await axiosInstance.get(
`${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('refreshToken', data.refreshToken);
return data.token;