-
Notifications
You must be signed in to change notification settings - Fork 927
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
loggedIn is false and user is not available in middleware when executed in server side. SSR:true and target as static #997
Comments
I'm getting this too! |
Hi @ramsane! This seems to be misconfiguration. Try the following config: auth: {
redirect: {
login: '/login',
logout: '/login',
home: false,
},
strategies: {
local: {
endpoints: {
login: {
url: '/users/login/',
method: 'post'
},
logout: false,
user: false, // must define the user endpoint to have user data
},
token: {
property: 'token', // the token property should be set here, `propertyName` in endpoint was deprecated.
type: 'Bearer', // should be "Bearer" if is jwt token
},
},
},
} I believe the token will be correctly handled now, but you still need to define the user endpoint, otherwise user will not be available. |
I have a backend that uses When I access $auth, loggedIn is False and token is set. And I wrote a simple plugin that fetches the user based on the token and set the user manually. I got that part. Thanks for clarifying that. Now, In login page, I wrote a middleware that checks for whether user is loggedIn or not and redirects if the user is authenticated. But $auth.loggedIn is false and token is not set in server to get the userInfo. But as soon as the page got loaded to the client, it gets data from cookies(probably) and makes loggedIn as true and get's the token. I can fetch the user and set the user with So, I think that the $auth not able to get loggedIn information when executed from the server. I hope the problem is clear now. |
@ramsane Ok, thank you for clarifying that! :) Can you make a repro? As this is a specific use case, I'll not be able to look at this issue without a repro. I know you said you can't because you're using with local api for authentication. But I think if the problem is related to middleware and server, then this issue should happen in our demo code too. |
It works fine in that demo. But I can see that, we are mentioning auth.js file in server middleware. Do I have to do that too. If required, I can share the complete config too. right now, I switched to spa(ssr: false) so that the middleware executes only on the client side. It works fine now. But I wanted to know the reason that's all. |
I'm facing the same issue. On a cold boot (local dev or on GCP App Engine)
Because my home page is different depending on the user's authentication status, this results in an SSR warning, which then leads to an even more cryptic error:
Here's my config:
And here is the token response: {
user: UserViewModel | null
token: string | null
refresh_token: string | null
} And here's my
|
Having the same issue |
Same issue here on |
Hey guys. Currently experiencing this as well ( Does this mean the auth middleware doesn't support SSR? Or is there any workaround besides switching to SPA? |
Facing same issue on
Would love to help but don't really know where to start from |
See #1197 for SSR issues |
@bmulholland So there is no issue here? or am i missing something? |
SSR issues are complex and highly dependent on your setup. I don't read anything in here that points to an identifiable issue in the auth module, but who knows. The issue I linked has a list of things to check. If you still have trouble after that, please do some debugging to figure out what's going on. I don't have your setup, so I can't debug it. I also don't have time to investigate all the issues that get filed here. |
Version
module: auth-next : 5.0.0-1610115973.9fdaa66
nuxt: 2.14.6
Nuxt configuration
mode:
Nuxt configuration
auth: {
redirect: {
login: '/login',
logout: '/login',
home: false,
},
strategies: {
local: {
endpoints: {
login: {
url: 'users/login/',
method: 'post',
propertyName: 'token',
},
logout: false,
user: false,
},
token: {
type: 'Token',
},
},
},
}
The text was updated successfully, but these errors were encountered: