-
I'm using https://github.com/TheRealFlyingCoder/remix-auth-socials
export const authenticator = new Authenticator<UserSession>(sessionStorage);
authenticator.use(
new GoogleStrategy({
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: `http://localhost:3000/auth/${SocialsProvider.GOOGLE}/callback`,
}, async (oauth) => {
const { profile: { displayName, _json } } = oauth;
const { sub } = _json;
const user = await getUserFromGoogleIdentity(sub);
// can I do this?
if (user === null) throw redirect(...)
return user
}),
"google",
); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Any error throw from the verify callback (the callback of the strategies) is caught by the Authenticator, then if you set Usually that should be enough, so you could setup any redirect using that option. But if you want to redirect directly from verify callback you could don't pass That said, I don't recommend you to throw redirects from the verify callback, that will mix your business logic of how to verify the user with the HTTP layer (redirects), instead you could throw directly from the verify callback and redirect in the loader or action where you call the |
Beta Was this translation helpful? Give feedback.
Any error throw from the verify callback (the callback of the strategies) is caught by the Authenticator, then if you set
failureRedirect
when callingauthenticator.authenticate
then the library will get theerror.message
and set it on the session before doing a redirect.Usually that should be enough, so you could setup any redirect using that option. But if you want to redirect directly from verify callback you could don't pass
failureRedirect
and instead pass thethrowOnError
option which will re-throw the error from the verify callback which will let you throw redirects.That said, I don't recommend you to throw redirects from the verify callback, that will mix your business logic of …