Skip to content

Commit

Permalink
Fix logout redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
TWilson023 committed Oct 30, 2024
1 parent f532760 commit f001e27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions apps/web/lib/auth/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { subscribe } from "@/lib/resend";
import { isStored, storage } from "@/lib/storage";
import { UserProps } from "@/lib/types";
import { ratelimit } from "@/lib/upstash";
import { PARTNERS_HOSTNAMES } from "@dub/utils";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { waitUntil } from "@vercel/functions";
import { sendEmail } from "emails";
Expand Down Expand Up @@ -415,6 +416,19 @@ export const authOptions: NextAuthOptions = {
};
return session;
},
redirect: async ({ url, baseUrl }) => {
// Allows relative callback URLs
if (url.startsWith("/")) return `${baseUrl}${url}`;

// Allows callback URLs on the same origin or from additionally allowed hostnames
if (
new URL(url).origin === baseUrl ||
PARTNERS_HOSTNAMES.has(new URL(url).host)
)
return url;

return baseUrl;
},
},
events: {
async signIn(message) {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/ui/layout/sidebar/user-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function UserDropdown() {
icon={LogOut}
onClick={() =>
signOut({
callbackUrl: "/login",
callbackUrl: `${window.location.origin}/login`,
})
}
/>
Expand Down

0 comments on commit f001e27

Please sign in to comment.