useSession() return null after Internationalized Routing, unless I refresh the page.
See original GitHub issueDescription 🐜
session is null after Internationalized Routing. Then if I refresh the current page, the session will return without problem;
Is this a bug in your own project?
Yes
How to reproduce ☕️
import Link from 'next/link'
export default function I18nLink(props) {
return (
<Link href="/another" locale="fr">
<a>To /fr/another</a>
</Link>
)
}
In one page or component I have the following code:
const ExampleComponent = () => {
const [session, loading] = useSession();
return (
{ session ? <div> session exist </div> : <div> session does not exist </div> }
)
In a page
const index = () => {
return (
<div>
<I18nLink />
<ExampleComponent />
</div>
)
}
export default index.
When I was already logined. And then click the I18nLink
, the page will transit to the new locate
without problem, but the session will be missing. Hence <div> session does not exist </div>
displayed.
My current workaround:
instead of using next router
, just simply use window.location = \newLocateUrl
to hard refresh the page.
Note:
I was using useSession()
to conditionally render certain components. If this wasn’t a right way to do so, just let me know.
Screenshots / Logs 📽
No response
Environment 🖥
Ubuntu Windows 10
Contributing 🙌🏽
Yes, I am willing to help solve this bug in a PR
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:5
Top Results From Across the Web
Next Auth useSession returning undefined on initial page load
I have an issue where my Next Auth useSession function is returning undefined on intial page load but works when hitting refresh on...
Read more >Advanced Features: Internationalized Routing - Next.js
js has built-in support for internationalized (i18n) routing since v10.0.0 . You can provide a list of locales, the default locale, and domain-specific...
Read more >CodeIgniter - Session Management - Tutorialspoint
This function will return NULL if the data you are trying to access is not available. $name = $this->session->userdata('name');. Example. Create a controller ......
Read more >Developing Python Web Applications with Flask
It routes the URL '/' request to main() which returns the hello-world message. ... I will show you how to run a Flask...
Read more >admin-bro-expressjs/plugin.js
Router() ; router.use(formidableMiddleware(formidableOptions)); routes. ... it causes; * logging out after every page refresh (if you use nodemon).
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
Yes, can confirm it’s a
next-18next
or probablyi18next
issue. And the solution is what @thomvand26 said.In terms of code for
next-18next
, the fix would be something like the following:It work for me. Thank you