mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-06-01 20:31:36 +02:00
c28265b89c
Signed-off-by: Ronni Skansing <rskansing@gmail.com>
22 lines
650 B
JavaScript
22 lines
650 B
JavaScript
// handle not ok typical responses such as unauthenticated, renew password and such
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
/**
|
|
* @param {import("./client").ApiResponse} apiResponse
|
|
* @returns {import("./client").ApiResponse} apiResponse
|
|
**/
|
|
export const immediateResponseHandler = (apiResponse) => {
|
|
// Unauthenticated move the user to the login page
|
|
if (apiResponse.statusCode === 401) {
|
|
goto('/login');
|
|
window.location.reload();
|
|
}
|
|
// If the user must renew their password, redirect to login
|
|
if (apiResponse.statusCode === 400 && apiResponse.error === 'New password required') {
|
|
goto('/login');
|
|
return;
|
|
}
|
|
return apiResponse;
|
|
};
|