Skip to content

Commit fe8193b

Browse files
committed
fix: set response status to 401 for unauthorized access in AdminForthRestAPI and prevent redirect to login on 401 status for login path in callApi function
1 parent 867b787 commit fe8193b

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

adminforth/modules/restApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
718718

719719

720720
if (!userRecord) {
721+
response.status = 401
721722
return { error: INVALID_MESSAGE };
722723
}
723724

@@ -748,6 +749,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
748749
});
749750
}
750751
} else {
752+
response.status = 401
751753
return { error: INVALID_MESSAGE };
752754
}
753755

adminforth/spa/src/utils/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export async function callApi({path, method, body, headers, silentError = false,
141141
const fullPath = `${import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH || ''}${path}`;
142142
try {
143143
const r = await fetch(fullPath, options);
144-
if (r.status == 401 ) {
144+
if (r.status == 401 && !path.includes('/login')) {
145145
useUserStore().unauthorize();
146146
useCoreStore().resetAdminUser();
147147
await redirectToLogin();

0 commit comments

Comments
 (0)