Skip to content
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

useSession is not updating after using router.replace(router.asPath) #4194

Open
woondossier opened this issue Aug 14, 2023 · 2 comments
Open
Labels
kind/bug Something isn't working status/triage

Comments

@woondossier
Copy link

woondossier commented Aug 14, 2023

What is the problem?

I'm trying to login using a popup window so I don't have to actually reload the page and lose state etc, just like the Auth0 spa package used to work.

I've got it working using router.replace(router.asPath) but only for the server side props, it returns my session etc but when I try to use the useSession hook I just keep getting an empty session object back, even when I try to pass the values from the SSP into the initialPublicData it still returns an empty session object.

Paste all your error logs here:

useSession:  {userId: null, isLoading: false}
getServerSideProps:  {name: 'my name', email: 'my email', userId: 12345, auth0Id: my auth0 id', etc }

Paste all relevant code snippets here:

const session = useSession({
    initialPublicData: publicData, //from gSSP
})

useEffect(() => {
    console.debug("useSession: ", session)
    console.debug("getServerSideProps: ", publicData)
}, [session, publicData])

What are detailed steps to reproduce this?

  1. login using a popup setting the cookies on our domain
  2. refresh the page without reloading using router.replace(router.asPath)
  3. useSession returns an empty session object with { userId: undefined, loading: false } and gSSP does get a proper session object with the logged in user

Run blitz -v and paste the output here:

Blitz version: 2.0.0-beta.31 (global)
Blitz version: 2.0.0-beta.31 (local)
Windows 10 | win32-x64 | Node: v18.16.0


 Package manager: npm

  System:
    OS: Windows 10 10.0.19045
    CPU: (6) x64 Intel(R) Core(TM) i5-9600K CPU @ 3.70GHz
    Memory: 13.06 GB / 31.94 GB
  Binaries:
    Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 9.3.0 - ~\AppData\Roaming\npm\npm.CMD
  npmPackages:
    @blitzjs/auth: 2.0.0-beta.31 => 2.0.0-beta.31
    @blitzjs/next: 2.0.0-beta.31 => 2.0.0-beta.31
    @blitzjs/rpc: 2.0.0-beta.31 => 2.0.0-beta.31
    @prisma/client: 5.0.0 => 5.0.0
    blitz: 2.0.0-beta.31 => 2.0.0-beta.31
    next: ^13.4.13 => 13.4.13
    prisma: 5.0.0 => 5.0.0
    react: ^18.2.0 => 18.2.0
    react-dom: ^18.2.0 => 18.2.0
    typescript: ^4.9.5 => 4.9.5

Please include below any other applicable logs and screenshots that show your problem:

No response

@woondossier woondossier added kind/bug Something isn't working status/triage labels Aug 14, 2023
@woondossier woondossier changed the title useSession is not updating after refreshing the page useSession is not updating after using router.replace(router.asPath) Aug 14, 2023
@siddhsuresh
Copy link
Member

Hey @woondossier would it be possible for you to share a minimal reproduction?

@woondossier
Copy link
Author

@siddhsuresh
I've made a clean project with auth setup and it worked and started adding parts of our login structure till it breaks and it seems to be caused by the third party login part of our setup.

As soon as I use the passport/next-auth route instead of the default auth login page it breaks the useSession() from updating to the current user while all the cookies etc are being set.

I've made a hardcoded auth0 passport strategy on a empty new test tenant with a user that can also be use to login using the default auth way.

The only thing that needs to be configured is the redis server which is located in src/redis.ts

for auth0 use
example@blitz-auth.example with password example123!

for the default login example code/scaffold use
example@blitz-auth.example with password testtesttest

the example can be found at https://github.com/woondossier/blitz-auth-example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working status/triage
Projects
None yet
Development

No branches or pull requests

2 participants