Can't set up properly Next.js's SSR
See original GitHub issueI’ve followed the examples displayed in the README, as well as looked for solutions in other frameworks but I simply can’t fix this problem.
Doing a little bit of debug and research, I can come to the conclusion that the cookie contained by the request may be not what the authStore expects, because, according to the examples, the key pb_auth= is set as the default, while my cookie has the following structure:
a_session_[code]_legacy=[token]
Also, if it has anything to do with this, the token stored in localStorage it’s not equal to the one served on the cookie.
As extra information, I leave the code I wrote.
type ServerRequest = IncomingMessage & {
cookies: Partial<{
[key: string]: string
}>
}
class CustomAuthStore extends BaseAuthStore {
public request: ServerRequest
public response: ServerResponse<IncomingMessage>
constructor (request: ServerRequest, response: ServerResponse<IncomingMessage>) {
super()
this.request = request
this.response = response
this.loadFromCookie(
this.request.headers.cookie ?? ''
)
}
save (token: string, model: User | Admin | null): void {
super.save(token, model)
this.response.setHeader('set-cookie', this.exportToCookie())
}
clear (): void {
super.clear()
this.response.setHeader('set-cookie', this.exportToCookie())
}
}
Versions: pocketbase v0.7.10; pocketbase (sdk) v0.7.4
Issue Analytics
- State:
- Created 10 months ago
- Comments:17 (4 by maintainers)
Top Results From Across the Web
react-hydration-error - Next.js
When css-in-js libraries are not set up for pre-rendering (SSR/SSG) it will often lead to a hydration mismatch. In general this means the...
Read more >Next.js SSR with API not building properly - Stack Overflow
I've set up a very basic blog project with dynamic SSR which fetches data from the Notion-API to generate static blog pages. Everything...
Read more >Implementing SSR in Next.js: Dynamic routing and prefetching
This happens because named, or static, routes have a higher priority than a dynamic route. For example, if you have declared a dynamic...
Read more >How to disable Server-Side Rendering in Next.js
Alternatively, you can use dynamic import. We will need to create a wrapper component and wrap any page where you want SSR disabled...
Read more >How to host a Next.js web app with server-side rendering ...
You can leave all build options as it is, because Amplify will automatically pick up as SSR and deploy it. For this to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’ve managed to get it working in the new
appdirectory, using (https://github.com/vvo/iron-session/issues/560#issuecomment-1324598048 as a base. The only thing to note is that any actions that would update theauthStorecan only happen in the client, fow now.lib/getUserFromCookie.tslib/pocketbase.tsAnd then, in
app/layout.tsxSo what I did for my solution is the following…
So the above helps me on the server and then for the client I have the following.