-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Key "github.com/gin-gonic/contrib/sessions" does not exist #533
Comments
Just a question, why would you want to load a config file each time in a middleware and setup the session, you only want to do this once at app startup, not for each request in a middlware, imagine it reading a config file each request... that would be slow. Your InitSessions middleware returns a handler func though, you could load the config file in the outer function, not the inner one which runs for each request. |
You are exactly right. But I haven't yet been able to do this. This is my ultimate goal. |
Are you saving the session, contrib sessions uses gorilla sessions behinds the scenes, and you have to first put something into, then save the session or there won't be anything there (no cookies, or session will be created). It looks like you are trying to retrieve "user" from the session, but I see nowhere where user is being put into the session and the session being saved first. |
It code isn't even getting to the "user" part. I'm doing the basic example from here: https://github.com/gin-gonic/contrib/tree/master/sessions It actually fails here: https://github.com/gin-gonic/contrib/blob/master/sessions/sessions.go#L146
|
Resolved. Refactored this and took consideration of your advice. Now the config, session and database are loaded and then placed into the context. Thanks |
paulm17, I have the same problem with you, can you share how you did it? what did you change in your code? |
@Firiyuu this thread is based on some old code. Now https://github.com/gin-contrib/sessions/blob/master/example/cookie/main.go (btw, maybe you forget to call middleware over handlers with |
You shlould call
before you call
check it ! |
@paulm17
|
sorry everyone. I moved over to Echo a year after and then to Vue after that. My go usage is strictly API now. |
This helped me: denisbakhtin/ginblog#1 (comment) 🤦 |
I'm able to get the basic examples to work, but trying to get it to work with my MVC skeleton using gin.
So my routes.go is this:
My auth.go is this:
Why am I seeing:
Seems that whatever is happening in InitSession is not readable in RequireLogin.
Thanks
The text was updated successfully, but these errors were encountered: