Skip to content

Commit

Permalink
Fix paths
Browse files Browse the repository at this point in the history
  • Loading branch information
RobVermeer committed Dec 29, 2023
1 parent 4992b60 commit a00cb4a
Show file tree
Hide file tree
Showing 37 changed files with 89 additions and 87 deletions.
2 changes: 1 addition & 1 deletion src/app/[locale]/admin/groups/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getGroupById } from "@/lib/groups/getGroupById"
import { SendEmails } from "./components/SendEmails"
import { notFound, redirect } from "next/navigation"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"

interface Props {
params: { id: string }
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/admin/groups/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RemoveGroup } from "./components/RemoveGroup"
import { Button } from "@/components/ui/button"
import Link from "next/link"
import { getServerSession } from "next-auth"
import { authOptions } from "../../api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { redirect } from "next/navigation"

export default async function AdminUsersPage() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/admin/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AdminTabs } from "@/components/AdminTabs"
import { ListTitle } from "@/components/ListTitle"
import { getServerSession } from "next-auth"
import { ReactNode } from "react"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { redirect } from "next/navigation"

interface Props {
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/admin/users/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getUsers } from "@/lib/users/getUsers"
import { RemoveUser } from "./components/RemoveUser"
import { getInitials } from "@/utils/string"
import { getServerSession } from "next-auth"
import { authOptions } from "../../api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { redirect } from "next/navigation"

export default async function AdminUsersPage() {
Expand Down
54 changes: 2 additions & 52 deletions src/app/[locale]/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,5 @@
import { prisma } from "@/lib/prisma"
import { updateFirstNameById } from "@/lib/users/updateFirstNameById"
import { PrismaAdapter } from "@next-auth/prisma-adapter"
import NextAuth, { AuthOptions, Session, User } from "next-auth"
import GoogleProvider from "next-auth/providers/google"
import EmailProvider from "next-auth/providers/email"
import { sendVerificationRequest } from "@/utils/send-verification-request"
import { trackIssue } from "@/lib/trackIssue"

export const authOptions: AuthOptions = {
adapter: PrismaAdapter(prisma),
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
profile: (profile) => ({
id: profile.sub,
name: profile.name,
firstName: profile.given_name,
email: profile.email,
emailVerified: profile.email_verified,
image: profile.picture,
}),
}),
EmailProvider({
server: "",
from: "Wishlist <[email protected]>",
sendVerificationRequest,
}),
],
callbacks: {
session: ({ session, user }: { session: Session; user: User }) => {
session.user.id = user.id
session.user.firstName = user.firstName
session.user.isAdmin = user.id === process.env.ADMIN_USER_ID

return session
},
},
events: {
signIn: async ({ profile, user, isNewUser }) => {
trackIssue("User sign in", "info", { ...user, isNewUser })

if (!isNewUser && !user.firstName && profile?.firstName) {
await updateFirstNameById(user.id, profile.firstName)
}
},
signOut: ({ session }) => {
trackIssue("User sign out", "info", session.user)
},
},
}
import { authOptions } from "@/lib/nextAuth"
import NextAuth from "next-auth"

const handler = NextAuth(authOptions)

Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/group/[groupId]/[wishlistId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { Wishlist } from "@/components/Wishlist"
import { getGroupById } from "@/lib/groups/getGroupById"
import { getWishlistById } from "@/lib/wishlists/getWishlistById"
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/group/[groupId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { NextIntlClientProvider } from "next-intl"
import { getMessages, getTranslations } from "next-intl/server"
import Link from "next/link"
import { notFound, redirect } from "next/navigation"
import { authOptions } from "../../api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"

export async function generateMetadata({ params }: Props): Promise<Metadata> {
const group = await getGroupById(params.groupId)
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "./globals.css"
import type { Metadata } from "next"
import { getServerSession } from "next-auth"
import { Ubuntu } from "next/font/google"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { Header } from "@/components/Header"
import { Toaster } from "@/components/ui/toaster"
import { headers } from "next/headers"
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/profile/bought/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { List } from "@/components/List"
import { getBoughtWishlistItemsForUser } from "@/lib/wishlistItems/getBoughtWishlistItemsForUser"
import { getServerSession } from "next-auth"
import { getTranslations } from "next-intl/server"
import { authOptions } from "../../api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { redirect } from "next/navigation"

interface Props {
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/profile/groups/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { pickMessages } from "@/utils/pick"
import { getServerSession } from "next-auth"
import { NextIntlClientProvider } from "next-intl"
import { getMessages, getTranslations } from "next-intl/server"
import { authOptions } from "../../api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { redirect } from "next/navigation"

interface Props {
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { pickMessages } from "@/utils/pick"
import { getServerSession } from "next-auth"
import { NextIntlClientProvider } from "next-intl"
import { getMessages, getTranslations } from "next-intl/server"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { redirect } from "next/navigation"

interface Props {
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/profile/wishlists/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { pickMessages } from "@/utils/pick"
import { getServerSession } from "next-auth"
import { NextIntlClientProvider } from "next-intl"
import { getMessages, getTranslations } from "next-intl/server"
import { authOptions } from "../../api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { redirect } from "next/navigation"

interface Props {
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/wishlist/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Metadata } from "next"
import { getTranslations } from "next-intl/server"
import { Wishlist } from "@/components/Wishlist"
import { getServerSession } from "next-auth"
import { authOptions } from "../../api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { redirect } from "next/navigation"

interface Props {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/groups/createGroupForUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { prisma } from "@/lib/prisma"
import { groupProperties } from "./publicProperties"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { revalidatePath } from "next/cache"
import { groupSchema } from "@/lib/schema"
import { getErrorMessage } from "@/lib/utils"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/groups/deleteGroupById.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use server"

import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { prisma } from "@/lib/prisma"
import { getServerSession } from "next-auth"
import { revalidatePath } from "next/cache"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/groups/followGroupById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { prisma } from "@/lib/prisma"
import { groupProperties } from "./publicProperties"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { revalidatePath } from "next/cache"
import { getErrorMessage } from "@/lib/utils"
import { getTranslations } from "next-intl/server"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/groups/getGroupById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { prisma } from "@/lib/prisma"
import { groupProperties } from "./publicProperties"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { cache } from "react"
import { getTranslations } from "next-intl/server"

Expand Down
2 changes: 1 addition & 1 deletion src/lib/groups/getGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { prisma } from "@/lib/prisma"
import { groupProperties } from "./publicProperties"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { cache } from "react"
import { getTranslations } from "next-intl/server"

Expand Down
2 changes: 1 addition & 1 deletion src/lib/groups/getGroupsForUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { prisma } from "@/lib/prisma"
import { groupProperties } from "./publicProperties"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { cache } from "react"
import { getTranslations } from "next-intl/server"

Expand Down
2 changes: 1 addition & 1 deletion src/lib/groups/leaveGroupById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { prisma } from "@/lib/prisma"
import { groupProperties } from "./publicProperties"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { revalidatePath } from "next/cache"
import { getErrorMessage } from "@/lib/utils"
import { getTranslations } from "next-intl/server"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/groups/updateGroupById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { prisma } from "@/lib/prisma"
import { groupProperties } from "./publicProperties"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { revalidatePath } from "next/cache"
import { groupSchema } from "@/lib/schema"
import { getErrorMessage } from "@/lib/utils"
Expand Down
52 changes: 52 additions & 0 deletions src/lib/nextAuth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { prisma } from "@/lib/prisma"
import { updateFirstNameById } from "@/lib/users/updateFirstNameById"
import { PrismaAdapter } from "@next-auth/prisma-adapter"
import { AuthOptions, Session, User } from "next-auth"
import GoogleProvider from "next-auth/providers/google"
import EmailProvider from "next-auth/providers/email"
import { sendVerificationRequest } from "@/utils/send-verification-request"
import { trackIssue } from "@/lib/trackIssue"

export const authOptions: AuthOptions = {
adapter: PrismaAdapter(prisma),
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
profile: (profile) => ({
id: profile.sub,
name: profile.name,
firstName: profile.given_name,
email: profile.email,
emailVerified: profile.email_verified,
image: profile.picture,
}),
}),
EmailProvider({
server: "",
from: "Wishlist <[email protected]>",
sendVerificationRequest,
}),
],
callbacks: {
session: ({ session, user }: { session: Session; user: User }) => {
session.user.id = user.id
session.user.firstName = user.firstName
session.user.isAdmin = user.id === process.env.ADMIN_USER_ID

return session
},
},
events: {
signIn: async ({ profile, user, isNewUser }) => {
trackIssue("User sign in", "info", { ...user, isNewUser })

if (!isNewUser && !user.firstName && profile?.firstName) {
await updateFirstNameById(user.id, profile.firstName)
}
},
signOut: ({ session }) => {
trackIssue("User sign out", "info", session.user)
},
},
}
2 changes: 1 addition & 1 deletion src/lib/reminders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { getServerSession } from "next-auth"
import { prisma } from "@/lib/prisma"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { revalidatePath } from "next/cache"
import { getErrorMessage } from "@/lib/utils"
import { getTranslations } from "next-intl/server"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/users/deleteUserById.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use server"

import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { prisma } from "@/lib/prisma"
import { getServerSession } from "next-auth"
import { revalidatePath } from "next/cache"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/users/getUsers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use server"

import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { prisma } from "@/lib/prisma"
import { getServerSession } from "next-auth"
import { getTranslations } from "next-intl/server"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/users/updateFirstNameById.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use server"

import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { prisma } from "@/lib/prisma"
import { getErrorMessage } from "@/lib/utils"
import { getServerSession } from "next-auth"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/users/updateProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { revalidatePath } from "next/cache"
import { getErrorMessage } from "@/lib/utils"
import { getTranslations } from "next-intl/server"
import { prisma } from "@/lib/prisma"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { getServerSession } from "next-auth"
// import sharp from "sharp"

Expand Down
2 changes: 1 addition & 1 deletion src/lib/wishlistItems/createWishlistItemForUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { prisma } from "@/lib/prisma"
import { wishlistItemProperties } from "./publicProperties"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { revalidatePath } from "next/cache"
import { z } from "zod"
import { getErrorMessage } from "@/lib/utils"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wishlistItems/deleteWishlistItemById.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use server"

import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { prisma } from "@/lib/prisma"
import { getServerSession } from "next-auth"
import { revalidatePath } from "next/cache"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wishlistItems/getBoughtWishlistItemsForUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { prisma } from "@/lib/prisma"
import { wishlistProperties } from "@/lib/wishlists/publicProperties"
import { wishlistItemProperties } from "./publicProperties"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { cache } from "react"
import { getTranslations } from "next-intl/server"

Expand Down
2 changes: 1 addition & 1 deletion src/lib/wishlistItems/toggleWishlistItemById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { prisma } from "@/lib/prisma"
import { wishlistItemProperties } from "./publicProperties"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { revalidatePath } from "next/cache"
import { getErrorMessage } from "@/lib/utils"
import { getTranslations } from "next-intl/server"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wishlistItems/updateWishlistItemById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { prisma } from "@/lib/prisma"
import { wishlistItemProperties } from "./publicProperties"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { revalidatePath } from "next/cache"
import { wishlistItemSchema } from "@/lib/schema"
import { getErrorMessage } from "@/lib/utils"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wishlists/createWishlistForUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { prisma } from "@/lib/prisma"
import { wishlistProperties } from "./publicProperties"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { revalidatePath } from "next/cache"
import { wishlistSchema } from "@/lib/schema"
import { z } from "zod"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wishlists/deleteWishlistById.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use server"

import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { prisma } from "@/lib/prisma"
import { getServerSession } from "next-auth"
import { revalidatePath } from "next/cache"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wishlists/getWishlistById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { cache } from "react"
import { prisma } from "@/lib/prisma"
import { wishlistProperties } from "./publicProperties"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/[locale]/api/auth/[...nextauth]/route"
import { authOptions } from "@/lib/nextAuth"
import { getTranslations } from "next-intl/server"

export const getWishlistById = cache(
Expand Down
Loading

0 comments on commit a00cb4a

Please sign in to comment.