wobsoriano / nuxt-clerk-template

Auth starts here with the Nuxt and Clerk Demo
https://nuxt-clerk-template.nuxt.dev
98 stars 11 forks source link

Token not refreshing? #14

Closed JoshuaPerk closed 5 months ago

JoshuaPerk commented 6 months ago

Has anyone else had issues with the JWT token expiring after 60 seconds (expected according to Clerk) but not refreshing (not expected)? image

I'm calling my Express backend using a composable that wraps useFetch with what (should be) a proper token.

export const useApiFetch = async (request, opts) => {
  const nuxtApp = useNuxtApp();
  const config = useRuntimeConfig();
  const token = await nuxtApp.$clerk.session.getToken();
  return useFetch(request, {
    baseURL: config.public.apiBaseUrl,
    headers: {
      Authorization: `Bearer ${token}`,
    },
    ...opts,
  });
};

I've tried without success to add useRequestHeaders as mentioned here (but I think this is for when calling the Nuxt server API). I also tried skipCache in hopes it would request a new, refreshed token.

My last resort is to use a custom JWT with a much longer expiration but this feels like it's circumventing the problem of the refresh not occuring.

JoshuaPerk commented 6 months ago

Temporarily solved by using a custom JWT which allows the extension of the expiration period

wobsoriano commented 5 months ago

Hey @JoshuaPerk, released another major version which reduces the bundle size of the app :) Also made the plugin simpler.

Let me know if it helps in any way!

Regarding token not refreshing, I haven't really encountered it but I'll let you know if I do.

wobsoriano commented 5 months ago

Closing this for now, Josh. Let me know if it gets fixed when you start migrating to the new versions of vue and h3 clerk. Feel free to reopen, though