diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index 84cc46056..23ec62ad8 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -1,60 +1,5 @@ -import { storeApi } from 'lib/woocomerce/storeApi'; -import { woocommerce } from 'lib/woocomerce/woocommerce'; -import { NextAuthOptions, Session, User } from 'next-auth'; -import { JWT } from 'next-auth/jwt'; -import NextAuth from 'next-auth/next'; -import CredentialsProvider from 'next-auth/providers/credentials'; - -export const authOptions = { - secret: process.env.NEXTAUTH_SECRET, - session: { - strategy: 'jwt' // Use JWT for session handling - }, - providers: [ - CredentialsProvider({ - name: 'woocommerce', - credentials: { - username: { label: 'Username', type: 'text', placeholder: 'Username' }, - password: { label: 'Password', type: 'password', placeholder: 'Password' } - }, - async authorize(credentials, req) { - if (!credentials?.username || !credentials?.password) { - return null; - } - const user = await woocommerce.login(credentials.username, credentials.password); - // If no error and we have user data, return it - if (user) { - return user; - } - // Return null if user data could not be retrieved - return null; - } - }) - ], - callbacks: { - async jwt({ token, user }: { token: JWT; user: User }) { - if (user) { - console.debug('Set token user', user); - token.user = user; - } - return token; - }, - async session({ session, token }: { session: Session; token: JWT }) { - console.debug('Set session token', token.user); - session.user = token.user; - return session; - }, - }, - events: { - async signIn() { - storeApi._seCartToken(''); - }, - async signOut() { - storeApi._seCartToken(''); - storeApi._setAuthorizationToken(''); - } - } -} satisfies NextAuthOptions; +import { authOptions } from "lib/auth/config"; +import NextAuth from "next-auth"; const handler = NextAuth(authOptions); export { handler as GET, handler as POST }; diff --git a/app/api/cart/route.ts b/app/api/cart/route.ts index 71374a6db..78c6aa26e 100644 --- a/app/api/cart/route.ts +++ b/app/api/cart/route.ts @@ -1,7 +1,7 @@ +import { authOptions } from 'lib/auth/config'; import { storeApi } from 'lib/woocomerce/storeApi'; import { getServerSession } from 'next-auth'; import { NextRequest, NextResponse } from 'next/server'; -import { authOptions } from '../auth/[...nextauth]/route'; export async function GET(req: NextRequest) { try { diff --git a/app/profile/orders/[id]/page.tsx b/app/profile/orders/[id]/page.tsx index d9d3a9502..a77ebc30b 100644 --- a/app/profile/orders/[id]/page.tsx +++ b/app/profile/orders/[id]/page.tsx @@ -1,5 +1,5 @@ -import { authOptions } from 'app/api/auth/[...nextauth]/route'; import Price from 'components/price'; +import { authOptions } from 'lib/auth/config'; import { woocommerce } from 'lib/woocomerce/woocommerce'; import { getServerSession } from 'next-auth'; import Image from 'next/image'; diff --git a/app/profile/orders/page.tsx b/app/profile/orders/page.tsx index 73e5decb9..94c0ab308 100644 --- a/app/profile/orders/page.tsx +++ b/app/profile/orders/page.tsx @@ -1,5 +1,5 @@ -import { authOptions } from 'app/api/auth/[...nextauth]/route'; import Price from 'components/price'; +import { authOptions } from 'lib/auth/config'; import { woocommerce } from 'lib/woocomerce/woocommerce'; import { getServerSession } from 'next-auth'; import Image from 'next/image'; diff --git a/app/profile/page.tsx b/app/profile/page.tsx index 6387d62e2..3e5c28bd8 100644 --- a/app/profile/page.tsx +++ b/app/profile/page.tsx @@ -1,5 +1,5 @@ -import { authOptions } from 'app/api/auth/[...nextauth]/route'; import LogoutButton from 'components/button/logout'; +import { authOptions } from 'lib/auth/config'; import { woocommerce } from 'lib/woocomerce/woocommerce'; import { getServerSession } from 'next-auth'; import Link from 'next/link'; diff --git a/app/search/[collection]/opengraph-image.tsx b/app/search/[collection]/opengraph-image.tsx deleted file mode 100644 index 0e2262cab..000000000 --- a/app/search/[collection]/opengraph-image.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import OpengraphImage from 'components/opengraph-image'; - -export const runtime = 'edge'; - -export default async function Image({ params }: { params: { collection: string } }) { - return await OpengraphImage({ title: '' }); -} diff --git a/app/search/[collection]/page.tsx b/app/search/[collection]/page.tsx deleted file mode 100644 index dfb07e3c0..000000000 --- a/app/search/[collection]/page.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { getCollection, getCollectionProducts } from 'lib/shopify'; -import { Metadata } from 'next'; -import { notFound } from 'next/navigation'; - -import Grid from 'components/grid'; -import ProductGridItems from 'components/layout/product-grid-items'; -import { defaultSort, sorting } from 'lib/constants'; - -export async function generateMetadata(props: { - params: Promise<{ collection: string }>; -}): Promise { - const params = await props.params; - const collection = await getCollection(params.collection); - - if (!collection) return notFound(); - - return { - title: collection.seo?.title || collection.title, - description: - collection.seo?.description || collection.description || `${collection.title} products` - }; -} - -export default async function CategoryPage(props: { - params: Promise<{ collection: string }>; - searchParams?: Promise<{ [key: string]: string | string[] | undefined }>; -}) { - const searchParams = await props.searchParams; - const params = await props.params; - const { sort } = searchParams as { [key: string]: string }; - const { sortKey, reverse } = sorting.find((item) => item.slug === sort) || defaultSort; - const products = await getCollectionProducts({ collection: params.collection, sortKey, reverse }); - - return ( -
- {products.length === 0 ? ( -

{`No products found in this collection`}

- ) : ( - - - - )} -
- ); -} diff --git a/app/search/layout.tsx b/app/search/layout.tsx index 050eba61a..f55b04097 100644 --- a/app/search/layout.tsx +++ b/app/search/layout.tsx @@ -1,6 +1,7 @@ import Footer from 'components/layout/footer'; import FilterList from 'components/layout/search/filter'; import { sorting } from 'lib/constants'; +import { Suspense } from 'react'; import ChildrenWrapper from './children-wrapper'; export default function SearchLayout({ children }: { children: React.ReactNode }) { @@ -11,7 +12,9 @@ export default function SearchLayout({ children }: { children: React.ReactNode }
- {children} + + {children} +
diff --git a/app/sitemap.ts b/app/sitemap.ts index ac463811a..9e13c01a3 100644 --- a/app/sitemap.ts +++ b/app/sitemap.ts @@ -1,4 +1,3 @@ -import { validateEnvironmentVariables } from 'lib/utils'; import { MetadataRoute } from 'next'; type Route = { @@ -13,8 +12,6 @@ const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL export const dynamic = 'force-dynamic'; export default async function sitemap(): Promise { - validateEnvironmentVariables(); - const routesMap = [''].map((route) => ({ url: `${baseUrl}${route}`, lastModified: new Date().toISOString() diff --git a/components/cart/add-to-cart.tsx b/components/cart/add-to-cart.tsx index 6a46fa5e2..7ecb19af6 100644 --- a/components/cart/add-to-cart.tsx +++ b/components/cart/add-to-cart.tsx @@ -11,7 +11,7 @@ function SubmitButton({disabled = false}: {disabled: boolean}) { 'relative flex w-full items-center justify-center rounded-full bg-blue-600 p-4 tracking-wide text-white'; return ( -