Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

Add auth to API routes

Khuram Niaz014b18f9984a
diff --git a/src/auth.config.ts b/src/auth.config.ts
index f870018..be0d666 100644
--- a/src/auth.config.ts
+++ b/src/auth.config.ts
@@ -20,10 +20,10 @@ export const authConfig = {
authorized({ auth, request: { nextUrl } }) {
const isLoggedIn = !!auth?.user;
const isOnDashboard = nextUrl.pathname.startsWith("/dashboard");
+ const isApiRoute = nextUrl.pathname.startsWith("/api");
- if (isOnDashboard) {
- if (isLoggedIn) return true;
- return false;
+ if (isOnDashboard || isApiRoute) {
+ return isLoggedIn;
} else if (isLoggedIn) {
return Response.redirect(new URL("/dashboard", nextUrl));
}
diff --git a/src/middleware.ts b/src/middleware.ts
index ec61cc8..389fd8d 100644
--- a/src/middleware.ts
+++ b/src/middleware.ts
@@ -6,8 +6,8 @@ export default NextAuth(authConfig).auth;
export const config = {
// https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
matcher: [
- // "/((?!api|_next/static|_next/image|.*\\.png$).*)",
"/dashboard",
"/dashboard/:path*",
+ "/api/((?!auth).*)",
],
};