mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 01:27:41 +00:00
Checkpoint 2
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
import { getAuthToken, setAuthToken } from '@app/reactQuery';
|
import { getAuthToken, setAuthToken , setMfaTempToken } from '@app/reactQuery';
|
||||||
|
|
||||||
// depreciated: go for apiRequest module in config/api
|
// depreciated: go for apiRequest module in config/api
|
||||||
export default class SecurityClient {
|
export default class SecurityClient {
|
||||||
|
static setMfaToken(tokenStr: string) {
|
||||||
|
setMfaTempToken(tokenStr);
|
||||||
|
}
|
||||||
|
|
||||||
static setToken(tokenStr: string) {
|
static setToken(tokenStr: string) {
|
||||||
setAuthToken(tokenStr);
|
setAuthToken(tokenStr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ export const apiRequest = axios.create({
|
|||||||
|
|
||||||
apiRequest.interceptors.request.use((config) => {
|
apiRequest.interceptors.request.use((config) => {
|
||||||
const token = getAuthToken();
|
const token = getAuthToken();
|
||||||
|
console.log('interceptors');
|
||||||
|
console.log('token', token);
|
||||||
|
console.log('config.headers', config.headers);
|
||||||
if (token && config.headers) {
|
if (token && config.headers) {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
config.headers.Authorization = `Bearer ${token}`;
|
config.headers.Authorization = `Bearer ${token}`;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { QueryClient } from '@tanstack/react-query';
|
import { QueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
// this is saved in react-query cache
|
// this is saved in react-query cache
|
||||||
|
export const MFA_TEMP_TOKEN_CACHE_KEY = ['infisical__mfa-temp-token'];
|
||||||
export const AUTH_TOKEN_CACHE_KEY = ['infisical__auth-token'];
|
export const AUTH_TOKEN_CACHE_KEY = ['infisical__auth-token'];
|
||||||
|
|
||||||
export const queryClient = new QueryClient({
|
export const queryClient = new QueryClient({
|
||||||
@@ -13,9 +14,13 @@ export const queryClient = new QueryClient({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// set token in memory cache
|
// set token in memory cache
|
||||||
|
export const setMfaTempToken = (token: string) =>
|
||||||
|
queryClient.setQueryData(MFA_TEMP_TOKEN_CACHE_KEY, token);
|
||||||
|
|
||||||
export const setAuthToken = (token: string) =>
|
export const setAuthToken = (token: string) =>
|
||||||
queryClient.setQueryData(AUTH_TOKEN_CACHE_KEY, token);
|
queryClient.setQueryData(AUTH_TOKEN_CACHE_KEY, token);
|
||||||
|
|
||||||
|
export const getMfaTempToken = () => queryClient.getQueryData(MFA_TEMP_TOKEN_CACHE_KEY) as string;
|
||||||
export const getAuthToken = () => queryClient.getQueryData(AUTH_TOKEN_CACHE_KEY) as string;
|
export const getAuthToken = () => queryClient.getQueryData(AUTH_TOKEN_CACHE_KEY) as string;
|
||||||
|
|
||||||
export const isLoggedIn = () => Boolean(getAuthToken());
|
export const isLoggedIn = () => Boolean(getAuthToken());
|
||||||
|
|||||||
Reference in New Issue
Block a user