Skip to content

Commit

Permalink
fix: check for secure callback URL and add Sentry message
Browse files Browse the repository at this point in the history
  • Loading branch information
agrattan0820 committed Apr 7, 2024
1 parent a44024a commit 46cc9b0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions apps/client/src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import NextAuth, { NextAuthOptions } from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import { db } from "database";
import { myDrizzleAdapter } from "@ai/components/my-drizzle-adapter";
import { captureMessage } from "@sentry/nextjs";

export const authOptions = (
req?: NextApiRequest | Request,
Expand All @@ -20,9 +21,20 @@ export const authOptions = (
? new URL(
req.cookies["next-auth.callback-url"],
).searchParams.get("nickname") ?? ""
: ""
: typeof req.cookies["__Secure-next-auth.callback-url"] ===
"string"
? new URL(
req.cookies["__Secure-next-auth.callback-url"],
).searchParams.get("nickname") ?? ""
: ""
: "";

if (!cookieNickname) {
captureMessage(
"No nickname was found when returning profile from Google callback.",
);
}

return {
id: profile.sub,
name: profile.name,
Expand All @@ -43,7 +55,7 @@ export const authOptions = (
// newUser: "/auth/new-user", // New users will be directed here on first sign in (leave the property out if not of interest)
},
callbacks: {
async session({ session, user }) {
session({ session, user }) {
session.user = user;
return session;
},
Expand Down

0 comments on commit 46cc9b0

Please sign in to comment.