Files
phishingclub/frontend/src/lib/api/middleware.js
T
Ronni Skansing c28265b89c removed unused legacy page
Signed-off-by: Ronni Skansing <rskansing@gmail.com>
2025-09-21 15:32:59 +02:00

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;
};