clerk / javascript

Official Javascript repository for Clerk authentication
https://clerk.com
MIT License
1.09k stars 240 forks source link

Feature: Caching of the session #827

Closed john--kane closed 1 year ago

john--kane commented 1 year ago

Package

Description

When using the in @clerk/nextjs , etc take time to recognise session state. Is it possible to add a revalidate flag or something like it to speed up this UI.

Current impact is that on every page load/transition a loading spinner is required to conditionally render part of the UI related to the clerk user.

Initial thoughts: use the Next13 loading.tsx as the place for this Clerk state check, or perhaps the provider needs some way to maintain state across page loads without going to clerk to reconfirm every time?

SokratisVidros commented 1 year ago

@john--kane I assume you are talking about the app-beta feature, right? @clerk/nextjs uses an interstitial page mechanism so as to have almost instance session state. Would you like to elaborate more on the request?

john--kane commented 1 year ago

@SokratisVidros Yes, app-beta, testing on NextJS 13. Can do, it could also be an incorrect implementation on my part but they way I've got it is. ClerkProvider at the root layout, middleware.ts catches auth state via withClerkMiddleware (which I think you're referring to as their interstitial method) and client Clerk UI components rendering some UI conditionally.

My main 'issue' is around the client side components in React. Despite the middleware + session being valid via Clerk, there is a noticeable delay between the loaded and active states in the UI. Implying an additional check.

End effect is that user sees a loading spinner for a noticeable period of time, which I was looking to reduce since the middleware and session are good to go from the NextJS server side.

Is there better/official solution for NextJS 13, e.g. server component approach instead? e.g. use case of showing the profile component conditionally when the user is logged in.

anagstef commented 1 year ago

@john--kane Hello! Thank you for reaching out! I understand your issue visually, but it would be helpful for us if you provided a demo of it. A sample of code or a code repository where this can be reproduced so that we can quickly identify the issue if there is one and address it or let you know how to work around this.

clerk-cookie commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

clerk-cookie commented 1 year ago

This issue was closed because it has been stalled for 10 days with no activity.

clerk-cookie commented 3 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.