You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Redirecting Users previous page After Authentication
#26
Hey, I want to redirect the user to the previous page with the search parameter 'redirectTo' after they've been authenticated
// $provider.callback.tsximporttype{LoaderArgs}from'@remix-run/server-runtime'importinvariantfrom'tiny-invariant'import{authenticator}from'~/services/auth.server'exportfunctionloader({ request, params }: LoaderArgs){invariant(typeofparams.provider==='string','provider is required')returnauthenticator.authenticate(params.provider,request,{successRedirect: '/dashboard',failureRedirect: '/login',})}// auth.server.tsauthenticator.use(newGoogleStrategy({clientID: process.env.GOOGLE_CLIENT_ID,clientSecret: process.env.GOOGLE_CLIENT_SECRET,callbackURL: `${getDomainEnv()}/${SocialsProvider.GOOGLE}/callback`,},async({ profile })=>{// Here, you would find or create a user in your database// console.log({ profile })constuser=awaitregisterPatients({name: profile._json.name,email: profile._json.email,password: profile.id,profile_image: profile._json.picture,isGoogle: true,})if(user.error){thrownewError(`${user.error.message}`)}returnuser.userData},),)
If anyone has a better idea to solve this, I'm open to suggestions.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Hey, I want to redirect the user to the previous page with the search parameter 'redirectTo' after they've been authenticated
If anyone has a better idea to solve this, I'm open to suggestions.
All reactions