Skip to content

Commit

Permalink
fix: use updated csrf token on first login
Browse files Browse the repository at this point in the history
  • Loading branch information
manchenkoff committed Jun 25, 2024
1 parent 34da1e4 commit 14f5c63
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions src/runtime/httpFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ function configureClientInterceptors(
}
}

function determineCredentialsMode() {
// Fix for Cloudflare workers - https://github.com/cloudflare/workers-sdk/issues/2514
const isCredentialsSupported = 'credentials' in Request.prototype;

if (!isCredentialsSupported) {
return undefined;
}

return 'include';
}

export function createHttpClient(logger: ConsolaInstance): $Fetch {
const options = useSanctumConfig();
const user = useSanctumUser();
Expand All @@ -64,24 +53,24 @@ export function createHttpClient(logger: ConsolaInstance): $Fetch {

const httpOptions: FetchOptions = {
baseURL: options.baseUrl,
credentials: determineCredentialsMode(),
credentials: 'include',
redirect: 'manual',
retry: options.client.retry,

async onRequest(context: FetchContext): Promise<void> {
await nuxtApp.runWithContext(() => {
for (const interceptor of requestInterceptors) {
interceptor(nuxtApp, context, logger);
}
});
for (const interceptor of requestInterceptors) {
await nuxtApp.runWithContext(async () => {
await interceptor(nuxtApp, context, logger);
});
}
},

async onResponse(context: FetchContext): Promise<void> {
await nuxtApp.runWithContext(() => {
for (const interceptor of responseInterceptors) {
interceptor(nuxtApp, context, logger);
}
});
for (const interceptor of responseInterceptors) {
await nuxtApp.runWithContext(async () => {
await interceptor(nuxtApp, context, logger);
});
}
},

async onResponseError({ request, response }): Promise<void> {
Expand Down

0 comments on commit 14f5c63

Please sign in to comment.