Do I need the redirect callback here?

Hi! I was try to send the user to the /home uri after the sign in workflow, but saw that I can do that with the redirect callback. I did read in the docs thought that I can just add the options for { callbackUrl: "http://localhost:3000/home" } in my signin() callback. So I was wondering do I even need the redirect callback declared in my auth.ts file? Code for Client:
<button
className="rounded-full bg-white/10 px-10 py-3 font-semibold text-white no-underline transition hover:bg-white/20"
onClick={
sessionData ? () => void signOut() : () => void signIn(
'credential',
{
callbackUrl: 'http://localhost:3000/home',
}
)
}
>
<button
className="rounded-full bg-white/10 px-10 py-3 font-semibold text-white no-underline transition hover:bg-white/20"
onClick={
sessionData ? () => void signOut() : () => void signIn(
'credential',
{
callbackUrl: 'http://localhost:3000/home',
}
)
}
>
Code for Auth.ts:
export const authOptions: NextAuthOptions = {
callbacks: {
session({ session, token }) {
// Deconstruct the user object from the token and add it to the session, don't want to send password to the client. Only information that we need
const { id, username, email, firstName, lastName, image } =
token.user;
session.user = { id, username, email, firstName, lastName, image };
console.log('SESSION callback session', session);
return session;
},
// Called first, before jwt is returned
jwt({ token, user }) {
user && (token.user = user);
return token;
},
redirect({ url, baseUrl }) {
if (url.startsWith('/')) return `${baseUrl}${url}`;
else if (new URL(url).origin === baseUrl) return url;
return baseUrl;
},
},
export const authOptions: NextAuthOptions = {
callbacks: {
session({ session, token }) {
// Deconstruct the user object from the token and add it to the session, don't want to send password to the client. Only information that we need
const { id, username, email, firstName, lastName, image } =
token.user;
session.user = { id, username, email, firstName, lastName, image };
console.log('SESSION callback session', session);
return session;
},
// Called first, before jwt is returned
jwt({ token, user }) {
user && (token.user = user);
return token;
},
redirect({ url, baseUrl }) {
if (url.startsWith('/')) return `${baseUrl}${url}`;
else if (new URL(url).origin === baseUrl) return url;
return baseUrl;
},
},
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server