web: fix reset password token flow and auth interceptor
This commit is contained in:
@@ -14,7 +14,7 @@ export async function requestPasswordResetRequest(email: string): Promise<void>
|
||||
}
|
||||
|
||||
export async function resetPasswordRequest(token: string, password: string): Promise<void> {
|
||||
await http.post("/auth/reset-password", { token, password });
|
||||
await http.post("/auth/reset-password", { token, new_password: password });
|
||||
}
|
||||
|
||||
export async function loginRequest(email: string, password: string, otpCode?: string, recoveryCode?: string): Promise<TokenPair> {
|
||||
|
||||
@@ -21,7 +21,16 @@ let refreshInFlight: Promise<void> | null = null;
|
||||
|
||||
function shouldSkipRefresh(config?: InternalAxiosRequestConfig): boolean {
|
||||
const url = config?.url ?? "";
|
||||
return url.includes("/auth/login") || url.includes("/auth/refresh");
|
||||
return (
|
||||
url.includes("/auth/login") ||
|
||||
url.includes("/auth/refresh") ||
|
||||
url.includes("/auth/register") ||
|
||||
url.includes("/auth/check-email") ||
|
||||
url.includes("/auth/verify-email") ||
|
||||
url.includes("/auth/resend-verification") ||
|
||||
url.includes("/auth/request-password-reset") ||
|
||||
url.includes("/auth/reset-password")
|
||||
);
|
||||
}
|
||||
|
||||
http.interceptors.response.use(
|
||||
|
||||
@@ -76,8 +76,11 @@ export function App() {
|
||||
return;
|
||||
}
|
||||
window.localStorage.setItem(PENDING_RESET_PASSWORD_TOKEN_KEY, resetToken);
|
||||
if (accessToken) {
|
||||
logout();
|
||||
}
|
||||
window.history.replaceState(null, "", "/");
|
||||
}, []);
|
||||
}, [accessToken, logout]);
|
||||
|
||||
useEffect(() => {
|
||||
const nav = extractNotificationNavigationFromLocation();
|
||||
@@ -221,10 +224,28 @@ function extractPasswordResetTokenFromLocation(): string | null {
|
||||
return null;
|
||||
}
|
||||
const url = new URL(window.location.href);
|
||||
if (!/^\/reset-password\/?$/i.test(url.pathname)) {
|
||||
if (!/^\/reset-password(?:\/[^/]+)?\/?$/i.test(url.pathname)) {
|
||||
return null;
|
||||
}
|
||||
return url.searchParams.get("token")?.trim() || null;
|
||||
const tokenFromQuery =
|
||||
url.searchParams.get("token")?.trim() ||
|
||||
url.searchParams.get("reset_token")?.trim();
|
||||
if (tokenFromQuery) {
|
||||
return tokenFromQuery;
|
||||
}
|
||||
const pathMatch = url.pathname.match(/^\/reset-password\/([^/]+)\/?$/i);
|
||||
if (pathMatch?.[1]?.trim()) {
|
||||
return pathMatch[1].trim();
|
||||
}
|
||||
if (url.hash) {
|
||||
const hash = url.hash.replace(/^#/, "");
|
||||
const hashParams = new URLSearchParams(hash);
|
||||
const tokenFromHash = hashParams.get("token")?.trim() || hashParams.get("reset_token")?.trim();
|
||||
if (tokenFromHash) {
|
||||
return tokenFromHash;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function inviteJoinErrorMessage(error: unknown): string {
|
||||
|
||||
Reference in New Issue
Block a user