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
What I want is, after check my email and password true, I want redirect to google auth page and after google auth true I want set the token to session and redirect to home. Is it possible to make it like that?
//This is the flowLogin->googleAuth->Home
//Front End consthandler=async(e: React.FormEvent<HTMLFormElement>)=>{e.preventDefault();setLoading(true);constres=awaitsignIn("credentials",{redirect: false,data: emailRef.current?.value,password: passwordRef.current?.value,});if(res?.error){toast.error(res?.error);setLoading(false);}else{Router.replace("/");Router.events.on("routeChangeComplete",success);}};
//APIexportdefaultNextAuth({session: {jwt: true,},providers: [Providers.Credentials({asyncauthorize(credentials: credentialsData,req: NextApiRequest){letclient;try{
client =awaitConnectDatabase();}catch(error){thrownewError("Failed connet to database.");}const checkEmail =awaitclient.db().collection("users").findOne({email: credentials.data});constcheckPhone=awaitclient.db().collection("users").findOne({phone: credentials.data});letvalidData={password: "",email: "",};if(!checkEmail&&!checkPhone){client.close();thrownewError("Email atau No HP tidak terdaftar.");}elseif(checkEmail){validData=checkEmail;}elseif(checkPhone){validData=checkPhone;}constcheckPassword=awaitVertifyPassword(credentials.password,validData.password);if(!checkPassword){client.close();thrownewError("Password Salah.");}client.close();returnvalidData;},}),],callbacks: {asyncsession(session){constdata=awaitgetSelectedUser(session.user!.email!);session.user=data.userData;returnPromise.resolve(session);},},});
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.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I want make a custom login use next Auth.
What I want is, after check my email and password true, I want redirect to google auth page and after google auth true I want set the token to session and redirect to home. Is it possible to make it like that?
Beta Was this translation helpful? Give feedback.
All reactions