File tree Expand file tree Collapse file tree 3 files changed +14
-18
lines changed
Expand file tree Collapse file tree 3 files changed +14
-18
lines changed Original file line number Diff line number Diff line change @@ -24,8 +24,6 @@ import PasswordRecovery from "components/Auth/PasswordRecovery";
2424import AuthLayout from "./AuthLayout" ;
2525import ExpertAuthLayout from "./components/Experts/AuthLayout" ;
2626import TrackPageChanges from "TrackPageChanges" ;
27- import { Alert , Button } from "@mui/material" ;
28- import { Snackbar } from "@material-ui/core" ;
2927
3028// TODO: add flux
3129
Original file line number Diff line number Diff line change @@ -69,17 +69,6 @@ function getApiBase(): string {
6969 return `${ protocol } //${ hostname } ${ effectivePort ? `:${ effectivePort } ` : "" } `
7070}
7171
72- let skipRedirect = false ;
73-
74- export async function runWithoutAuthRedirect ( functionToRun : ( ) => Promise < any > ) {
75- skipRedirect = true ;
76- try {
77- return await functionToRun ( ) ;
78- } finally {
79- skipRedirect = false ;
80- }
81- }
82-
8372const cookieFetch = async ( url : string , init : any ) => {
8473 const response = await fetch ( url , {
8574 ...init ,
@@ -90,20 +79,30 @@ const cookieFetch = async (url: string, init: any) => {
9079
9180 if ( response . status === 401 &&
9281 ! path . includes ( "login" ) &&
93- ! path . includes ( "register" ) &&
94- ! skipRedirect ) {
82+ ! path . includes ( "register" ) ) {
9583 window . location . href = `/login?returnUrl=${ window . location . pathname } ` ;
9684 }
9785
9886 return response ;
9987}
10088
89+ const cookieFetchWithoutRedirect = async ( url : string , init : any ) => {
90+ const response = await fetch ( url , {
91+ ...init ,
92+ credentials : "include"
93+ } ) ;
94+
95+ return response ;
96+ }
97+
10198const basePath = getApiBase ( )
10299const authService = new AuthService ( )
103100const apiConfig = {
104101 basePath : basePath ,
105102}
106103
104+ export const accountApiWithoutRedirect = new AccountApi ( apiConfig , undefined , cookieFetchWithoutRedirect ) ;
105+
107106let ApiSingleton : Api ;
108107ApiSingleton = new Api (
109108 new AccountApi ( apiConfig , undefined , cookieFetch ) ,
Original file line number Diff line number Diff line change 11import { LoginViewModel , RegisterViewModel } from '../api' ;
2- import ApiSingleton , { runWithoutAuthRedirect } from "../api/ApiSingleton" ;
2+ import ApiSingleton , { accountApiWithoutRedirect } from "../api/ApiSingleton" ;
33import decode from "jwt-decode" ;
44
55
@@ -29,8 +29,7 @@ export default class AuthService {
2929
3030 public async getUser ( ) {
3131 try {
32- const accountData = await runWithoutAuthRedirect ( ( ) =>
33- ApiSingleton . accountApi . accountGetUserSummary ( ) ) ;
32+ const accountData = await accountApiWithoutRedirect . accountGetUserSummary ( ) ;
3433 if ( accountData ) {
3534 this . _user = {
3635 id : accountData . userId ! ,
You can’t perform that action at this time.
0 commit comments