-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Setting access token cookie? #2142
Comments
You can take a look at the user management example here: How to login the user: Set to use loopback token in server: |
If I'm understanding this correctly: Step 1:
Step 2:
But I've followed this example and the cookie never gets set. I don't see it in Chrome dev tools. Is User.login() supposed to set a cookie? Or are you supposed to do that manually? If so, how exactly are you supposed to set the cookie? Because I've tried that and it didn't work. If I navigate to a protected route I get 401, Authorization Required. Double checked the cookie was set, copy-pasted it on the end of the url like so: It's just not using the cookie. |
EUREKA. I got it to work. The cookie wasn't being signed. Sorry, I'm pretty much new to Express and lower-level stuff like this. I remembered reading that the cookie had to be signed but it slipped my mind that I had to pass "signed: true". |
@kenmorechalfant Glad you got it working. ;) Closing. |
@kenmorechalfant Could you dump the snippet of how exactly you signed the cookie and where did you passed "signed:true"? I'm facing exactly the same problem. Thanks |
@mkumr Yes, I haven't touched this code in months but here it is, hope it helps: routes.js
|
Do you need to set up cookieParser middleware? I did "session:before": { in middleware.json but node complained ${cookieSecret} does not resolve to a valid value. "cookieSecret" must be resolvable by app.get()., Anyone know how to resolve the cookieSecret? |
Find the solution, I need to set an express field like app.set('cookieSecret', 'kitty'); cookie-parser and session packages are required too. |
@lazydino , what do you mean by "cookie-parser and session packages are required too"? |
@fabianorodrigo cookie-parser is middleware. You must |
@kenmorechalfant thanks so much bro. i love you so much, this has been really helpful :) |
With LB3, I need token in cookie, a way for doing itIn
You alse need to install
In production you shoud have a different secret In
Be sure to have |
@superkhau Don't you think the above comment added to the docs? 😞 |
I want to use a cookie to keep a user logged in.
On this page here they say
Seemed simple enough. I figured the cookies were set by Loopback automatically during the login process but it's still not working, I check my cookies in Chrome dev tools and none are set.
Am I missing something? Otherwise, what's the best way to hook into the login method to have set the cookie/header?
I found docs on the
loopback.token()
method here, which says exactly where it checks for the token.The text was updated successfully, but these errors were encountered: