diff --git a/examples/apps/auth-sample/next.config.js b/examples/apps/auth-sample/next.config.js index 3dd7ef1..91ef62f 100644 --- a/examples/apps/auth-sample/next.config.js +++ b/examples/apps/auth-sample/next.config.js @@ -1,4 +1,6 @@ /** @type {import('next').NextConfig} */ -module.exports = { +const nextConfig = { reactStrictMode: true, }; + +module.exports = nextConfig; diff --git a/examples/apps/auth-sample/src/middleware.ts b/examples/apps/auth-sample/src/middleware.ts new file mode 100644 index 0000000..28fd028 --- /dev/null +++ b/examples/apps/auth-sample/src/middleware.ts @@ -0,0 +1,22 @@ +import { NextResponse } from "next/server"; + +export function middleware() { + // retrieve the current response + const res = NextResponse.next() + + // add the CORS headers to the response + res.headers.append('Access-Control-Allow-Credentials', "true") + res.headers.append('Access-Control-Allow-Origin', '*') // replace this your actual origin + res.headers.append('Access-Control-Allow-Methods', 'GET,DELETE,PATCH,POST,PUT') + res.headers.append( + 'Access-Control-Allow-Headers', + 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version' + ) + + return res +} + +// specify the path regex to apply the middleware to +export const config = { + matcher: '/api/:path*', +} \ No newline at end of file diff --git a/examples/apps/auth-sample/src/pages/middleware.ts b/examples/apps/auth-sample/src/pages/middleware.ts deleted file mode 100644 index 0b97b1d..0000000 --- a/examples/apps/auth-sample/src/pages/middleware.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { NextResponse } from 'next/server' -import type { NextRequest } from 'next/server' - -export function middleware(req: NextRequest) { - const res = NextResponse.next(); - - res.headers.set('Access-Control-Allow-Credentials', 'true'); - res.headers.set('Access-Control-Allow-Origin', '*'); - res.headers.set('Access-Control-Allow-Methods', 'GET,OPTIONS,PATCH,DELETE,POST,PUT'); - res.headers.set('Access-Control-Allow-Headers', 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, Authorization'); - - if (req.method === 'OPTIONS') { - return new NextResponse(null, { status: 200, headers: res.headers }); - } - - return res; -} - -export const config = { - matcher: '/api/:path*', -} \ No newline at end of file