Skip to content

Commit fad511e

Browse files
committed
fix: fix handler
1 parent 4021f30 commit fad511e

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

hwproj.front/src/App.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import PasswordRecovery from "components/Auth/PasswordRecovery";
2424
import AuthLayout from "./AuthLayout";
2525
import ExpertAuthLayout from "./components/Experts/AuthLayout";
2626
import TrackPageChanges from "TrackPageChanges";
27-
import {Alert, Button} from "@mui/material";
28-
import {Snackbar} from "@material-ui/core";
2927

3028
// TODO: add flux
3129

hwproj.front/src/api/ApiSingleton.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff 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-
8372
const 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+
10198
const basePath = getApiBase()
10299
const authService = new AuthService()
103100
const apiConfig = {
104101
basePath: basePath,
105102
}
106103

104+
export const accountApiWithoutRedirect = new AccountApi(apiConfig, undefined, cookieFetchWithoutRedirect);
105+
107106
let ApiSingleton: Api;
108107
ApiSingleton = new Api(
109108
new AccountApi(apiConfig, undefined, cookieFetch),

hwproj.front/src/services/AuthService.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {LoginViewModel, RegisterViewModel} from '../api';
2-
import ApiSingleton, {runWithoutAuthRedirect} from "../api/ApiSingleton";
2+
import ApiSingleton, {accountApiWithoutRedirect} from "../api/ApiSingleton";
33
import 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!,

0 commit comments

Comments
 (0)