Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Fix logout redirect

Tim Wilsonf001e279e461
diff --git a/apps/web/lib/auth/options.ts b/apps/web/lib/auth/options.ts
index 765af3ceac..3fa12b7396 100644
--- a/apps/web/lib/auth/options.ts
+++ b/apps/web/lib/auth/options.ts
@@ -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";
@@ -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) {
diff --git a/apps/web/ui/layout/sidebar/user-dropdown.tsx b/apps/web/ui/layout/sidebar/user-dropdown.tsx
index fa8c36ee0b..ab80248030 100644
--- a/apps/web/ui/layout/sidebar/user-dropdown.tsx
+++ b/apps/web/ui/layout/sidebar/user-dropdown.tsx
@@ -44,7 +44,7 @@ export default function UserDropdown() {
icon={LogOut}
onClick={() =>
signOut({
- callbackUrl: "/login",
+ callbackUrl: `${window.location.origin}/login`,
})
}
/>