useSession is not updating after using router.replace(router.asPath)
- Dominant language
- TypeScript
- Stars
- 14.1k
- Forks
- 803
- PR merge metrics
- No merged PRs in 30d
Description
### 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_
Contributor guide
Assessment
This issue has not been assessed yet.