bugfix: organization not selected problem fixed. being logged out too often fixed.
This commit is contained in:
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user