Skip to content

Commit cc8370c

Browse files
committed
Merge branch 'small_fixes' into dev_auth
2 parents c458309 + fad511e commit cc8370c

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

HwProj.APIGateway/HwProj.APIGateway.API/Controllers/AccountController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public async Task<IActionResult> RefreshToken()
155155
}
156156

157157
[HttpPost("logout")]
158+
[ProducesResponseType((int)HttpStatusCode.OK)]
158159
public IActionResult Logout()
159160
{
160161
ClearTokenCookie();

HwProj.APIGateway/HwProj.APIGateway.API/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void Configure(IApplicationBuilder app, IHostEnvironment env)
124124

125125
app.UseRouting();
126126
app.UseCors(x => x
127-
.AllowAnyMethod()
127+
.WithMethods("GET")
128128
.AllowAnyHeader()
129129
.SetIsOriginAllowed(_ => true)
130130
.AllowCredentials());

hwproj.front/src/api/ApiSingleton.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ const cookieFetch = async (url: string, init: any) => {
7575
credentials: "include"
7676
});
7777

78+
const path = window.location.pathname;
79+
80+
if (response.status === 401 &&
81+
!path.includes("login") &&
82+
!path.includes("register")){
83+
window.location.href = `/login?returnUrl=${window.location.pathname}`;
84+
}
85+
86+
return response;
87+
}
88+
89+
const cookieFetchWithoutRedirect = async (url: string, init: any) => {
90+
const response = await fetch(url, {
91+
...init,
92+
credentials: "include"
93+
});
94+
7895
return response;
7996
}
8097

@@ -84,6 +101,8 @@ const apiConfig = {
84101
basePath: basePath,
85102
}
86103

104+
export const accountApiWithoutRedirect = new AccountApi(apiConfig, undefined, cookieFetchWithoutRedirect);
105+
87106
let ApiSingleton: Api;
88107
ApiSingleton = new Api(
89108
new AccountApi(apiConfig, undefined, cookieFetch),

hwproj.front/src/services/AuthService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {LoginViewModel, AccountApi, RegisterViewModel} from '../api';
2-
import ApiSingleton from "../api/ApiSingleton";
1+
import {LoginViewModel, RegisterViewModel} from '../api';
2+
import ApiSingleton, {accountApiWithoutRedirect} from "../api/ApiSingleton";
33
import decode from "jwt-decode";
44

55

@@ -29,7 +29,7 @@ export default class AuthService {
2929

3030
public async getUser() {
3131
try {
32-
const accountData = await ApiSingleton.accountApi.accountGetUserSummary();
32+
const accountData = await accountApiWithoutRedirect.accountGetUserSummary();
3333
if (accountData) {
3434
this._user = {
3535
id: accountData.userId!,

0 commit comments

Comments
 (0)