Help redirecting user to home page after successful sign in #2371
Answered
by
balazsorban44
LGmatrix13
asked this question in
Help
-
Here is my code: import { providers, signIn, getSession } from "next-auth/client";
import Button from "../../components/Button";
function Login({ providers }) {
return (
<>
{Object.values(providers).map((provider) => (
<a key={provider.name} onClick={() => signIn(provider.id)}>
<Button login={true} name={provider.name} id={provider.id} />
</a>
))}
</>
);
}
export async function getServerSideProps(context) {
const { req, res } = context;
const session = await getSession({ req });
if (session && res && session.accessToken) {
res.writeHead(302, {
Location: "/",
});
res.end();
return;
}
return {
props: {
session: null,
providers: await providers(context),
},
};
}
export default Login; Every time I test it, it goes back to the login page. The user successfully authenticates; however, they remain on the login page. Any resolution? Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
balazsorban44
Jul 14, 2021
Replies: 1 comment 1 reply
-
https://next-auth.js.org/getting-started/client#specifying-a-callbackurl
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
LGmatrix13
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://next-auth.js.org/getting-started/client#specifying-a-callbackurl
signIn(provider.id, {callbackUrl: "/page-you-want-to-send-user-after-login"})