Reputation: 93
I have a Sails application and the authentication using passport works just fine when it is a single domain app (steps as in Passport Doc). I am now trying to convert the app to using subdomains (foo.example.com, bar.example.com), all of which points to the same sails server. The session works only for the same sub-domain, for example, if the user is logging in from foo.example.com, then the user is able to access pages under the same sub domain...but not under bar.example.com. req.isAuthenticated() is returning false when redirecting to a subdomain different from the one that was authenticated.
How can I ensure the authentication is across the sub-domains? Any help is much appreciated.
I am using [email protected]/[email protected].
Upvotes: 1
Views: 729
Reputation: 1178
Out of the box, Sails uses express-session for session middleware, allowing apps to support all the same functionality available within the express-session package.
To facilitate sharing the same session across multiple subdomains (foo.example.com, bar.example.com), two options need to be configured in the config/session.js file of your Sails app.
session: {
cookie: {
domain : '.example.com',
sameSite : false
}
}
It is worth noting that cookie.sameSite is an attribute that has not yet been fully standardized, and may change in the future. This also means many clients may ignore this attribute until they understand it.
It is most likely for this reason it is not included in the Sails documentation here. A more complete list of available options for express-session can be found here.
Another way to manage sessions across multiple subdomains can be found in this stackoverflow question.
Upvotes: 2