-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing the service worker config #307
base: master
Are you sure you want to change the base?
Conversation
There's a problem with this if you log in with one user, then log in again as another user, it doesn't refresh and still uses the old user. |
@pashpashpash hmmmm, that's odd. What browser are you using? Are you seeing a problem with the service worker? I did guard the router refresh behind the service worker ready & so I could ensure auth state was in sync with the new magic url method. I should do the same with login, only allow it if the service worker is registered and ready—since we rely on that. |
I'm on Chrome. It would also be helpful to have some documentation on the flows between the service worker, the client, and the server side rendering processes. I.e. if the server renders conditionally based on currentUser, but that user changes, will the page reload? Or will we need to include a reload in the clientside code. Explaining what we should expect. Thanks! |
Another issue I found is that server actions seem to drop the current user (currentUser=null), even though when SSR'ing a page that later calls the server action, the server says there is a currentUser. |
Yeah, upon further inspection, it looks like server actions are sent as POST requests, which in your service worker setup:
Means that the firebase auth headers are not included in the request. So, naturally, the action tries to run: And gets currentUser === null. |
@jamesdaniels Okay I fixed this by allowing POST as well as GET requests in your service worker fetch event listener:
Please let me know if this is bad practice. But it seems to work fine. Idk |
@pashpashpash good catch thanks, i'll address that |
Sorry to keep bugging you, but I'm still getting a weird bug where the auth state randomly tells me that the current user is null, when attempting a server action. Example scenario:
The most frustrating part about this bug is it seemingly happens at random, it feels ephemeral. Often the button works fine, and subsequent button clicks with other server actions are authenticated. But then randomly later on it shows the user as unauthenticated again. No page refreshes or anything. Same page, just a different point in time. EDIT:
|
Getting the NextJS codelab fixed up, this PR is intended to be shipped alongside cl/671476274
getAuthenticatedAppForUser
, fixes Question: What is "getAuthenticatedAppForUser" for? #274TODO: