bugfix: organization not selected problem fixed. being logged out too often fixed.

This commit is contained in:
2026-07-12 17:51:31 +03:30
parent 39935688ad
commit 901d838a2c
14 changed files with 490 additions and 22 deletions

View File

@@ -30,7 +30,6 @@ function isPublicInvitationRequest(url: string | undefined): boolean {
function shouldSkipRefreshRetry(url: string | undefined): boolean {
if (!url) return false;
return (
url.includes('/auth/profile') ||
url.includes('/auth/refresh') ||
url.includes('/auth/login') ||
url.includes('/auth/register') ||
@@ -57,13 +56,29 @@ apiClient.interceptors.response.use(
originalRequest._retry = true;
try {
// ✅ refresh via cookie (no body needed ideally)
// Refresh access token, then restore selected organization context on the new JWT.
await axios.post(
`${process.env.NEXT_PUBLIC_API_URL}/auth/refresh`,
{},
{ withCredentials: true }
{ withCredentials: true },
);
const orgId =
typeof window !== 'undefined'
? localStorage.getItem('currentOrganizationId')
: null;
if (orgId) {
try {
await axios.post(
`${process.env.NEXT_PUBLIC_API_URL}/auth/select-organization`,
{ organizationId: orgId },
{ withCredentials: true },
);
} catch {
/* original retry may still succeed if refresh preserved organizationId */
}
}
return apiClient(originalRequest);
} catch (refreshError) {
if (typeof window !== 'undefined') {