-
Notifications
You must be signed in to change notification settings - Fork 141
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
How to redirect user after passport login? #73
Comments
You can use For example: <h1>Login</h1>
<form action="/auth/local?next=/profile" method="post">
<input type="text" name="identifier" placeholder="username or email">
<input type="password" name="password" placeholder="password">
<input type="hidden" name="next" value="/" >
<button type="submit">login</button>
</form> Look source for understanding: https://github.com/tjwebb/sails-auth/blob/master/api/controllers/AuthController.js#L118 // Upon successful login, optionally redirect the user if there is a
// `next` query param
if (req.query.next) {
res.status(302).set('Location', req.query.next);
} For google auth, use For example: var passport = require('passport')
, GoogleStrategy = require('passport-google').Strategy;
passport.use(new GoogleStrategy({
returnURL: 'http://www.example.com/auth/google/return?next=/profile',
realm: 'http://www.example.com/'
},
function(identifier, profile, done) {
User.findOrCreate({ openId: identifier }, function(err, user) {
done(err, user);
});
}
)); Unfortunately, I am unable to check it out now. But the idea - it should work. |
Thank you @kulakowka for your response. I've managed to achieve the desired result by editing the var _ = require('lodash');
var _super = require('sails-auth/config/passport');
_.merge(exports, _super);
_.merge(exports, {
passport: {
google: {
options: {
clientID: '...',
clientSecret: '...',
callbackURL: 'http://localhost:1337/auth/google/callback?next=/'
}
}
}
}); However, I have two problems with it:
Thank you! |
Maybe you can use Then in action The endpoint for redirection may be stored in a cookie, for example. |
That's a smart idea @kulakowka, thanks! However, I still don't like the idea of overriding the |
It would be nice to have some configuration like redirect url on login/signup, just like https://github.com/jaumard/sails-hook-passport does. |
Below solution works perfectly fine. |
Hello!
I'm using passport login and
google
provider. After logging in, Sails returns JSON document with profile information. How do I redirect client to the page of my choice instead (e.g. homepage or profile page)?Thank you.
The text was updated successfully, but these errors were encountered: