Comments (8)
from sessions.
Ahh, I forgot to add the first part to my original question. And I didn't realize that the random key was problematic in that way, thanks. Changing this results in the ViewsController referencing an existing session created in the UserController instead of a new one previously, but all of the values added to the "Values" map by that same Controller are still not there for whatever reason. I have added an "isAuth" method to both the ViewsController and UserController to check to see the users that were added the "Values" map :
func isAuth(res http.ResponseWriter, req *http.Request){
newSession, _ := session.Store.Get(req, "cookie-name")
user, ok := newSession.Values["user"].(models.User)
if !user.Authenticated || !ok{
newSession.Save(req, res)
res.WriteHeader(http.StatusUnauthorized)
render.JSON(res, req, m{"error": "not authorized})
return
}
fmt.Println("values:", newSession.Values, "and user", user)//Prints expected values in the UserController, but not for the ViewsController
render.JSON(res, req, user)
}
When this method is hit in the UserController, it returns session values as expected, but when the same method is hit in the ViewsController, the session values map is still empty.
from sessions.
Okay, so I noticed that when session values are saved on a particular path prefix, they can ONLY be accessed on those path prefixes, and not anywhere else. I'm not sure if that's by design, or if there's something I have to change in my code to give every path access to the users in the session, but I was considering wrapping the *sessions.CookieStore
object in a struct with a map[interface{}]interface{}
field as an accompanying field to store the session values to allow for persistence.
from sessions.
from sessions.
Sorry for the absence, I ran into a few hurdles along the way. So in my "session" package where I have my "Store
" object of type *sessions.CookieStore
, I also have a "Ctx
" object of type context.Context
which both my ViewsController
and UserController
access, with the UserController
sending user data into the context, and the ViewsController
accessing them to render the pages using that data. Is this way concurrency safe?
from sessions.
from sessions.
I'm storing values in a global context object in my session package, and I have both my Views and User controllers store and retrieve values from it, so I appear to be doing the latter. The challenge I'm having then is how to I send a request scope context from one controller to another? On the front end, after the user signs in, Javascript sends the data to my UserController
via fetch
request, which is then intercepted by a middleware that parses the data into a User object, which is then put into a request scoped context and sent to the /api/users/signin
route. That route then stores the user in a session, and sends JSON back to the frontend, which then reroutes to the /
route. I'm not sure how to restructure my code to allow requests scoped contexts to be sent from one controller serving one path prefix to another controller serving another. Is there a particular model or pattern I have to follow?
from sessions.
This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.
from sessions.
Related Issues (20)
- deleted HOT 1
- Session doesn't cleanup HOT 3
- [question] How can I logout of a user from all other sessions except current one
- flash messages are not lost and are always saved when using gorilla mux HOT 3
- [bug] "More Examples" link in readme just links back to this repo HOT 1
- [question] Is there a way to store session data in file system and not in cookie HOT 1
- A question about deleting sessions HOT 3
- Changed auth/encryption key prevents the signed in user from accessing the webpage again HOT 16
- ⚠️ The Gorilla Toolkit is Looking for a New Maintainer HOT 2
- [feature] Add method to get cookie (to be used for request in tests) HOT 2
- SameSite is not set in the default path HOT 2
- Saving OAuth2 pointer in sessions HOT 1
- redigo: get on closed pool HOT 4
- securecookie: error - caused by: gob: name not registered for interface: "map[string]map[int]string" HOT 3
- [BUG] FilesystemStore MaxAge does not allow cookies until browser closes HOT 3
- Session still exists after setting MaxAge = -1
- [FEATURE] <Adding support for Partitioned attribute for 3rd Party Cookie deprecation> HOT 3
- FilesystemStore is vulnerable to directory traversal attacks HOT 2
- [Bug] unknown field 'Partitioned' in struct literal of type http.Cookie HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sessions.