adds a custom redirect callback that also let's urls with origin WEBSITE-URL (app.cal.com) pass, otherwise redirected to cal.com instead of app.cal.com on callback

fix/login-redirect
Agusti Fernandez Pardo 2022-05-16 18:47:49 +02:00
parent 4afb2946a7
commit 6842c13ea1
1 changed files with 7 additions and 0 deletions

View File

@ -434,5 +434,12 @@ export default NextAuth({
return false;
},
async redirect({ url, baseUrl }) {
// Allows relative callback URLs
if (url.startsWith("/")) return `${baseUrl}${url}`;
// Allows callback URLs on the same origin
else if (new URL(url).origin === baseUrl || WEBSITE_URL) return url;
return baseUrl;
},
},
});