Skip to content

Commit

Permalink
Fix middleware + auth config types
Browse files Browse the repository at this point in the history
  • Loading branch information
pheralb committed Mar 7, 2024
1 parent 75ad75d commit cd74648
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const { auth } = NextAuth(authConfig);

const middleware = async (req: NextRequest, isLoggedIn: boolean) => {
try {

const { nextUrl } = req;
const isApiAuthRoute = nextUrl.pathname.startsWith(apiAuthPrefix);
const isPublicRoute = publicRoutes.includes(nextUrl.pathname);
Expand Down Expand Up @@ -64,7 +65,7 @@ export default auth((req) => middleware(req, !!req.auth));

export const config = {
matcher: [
"/((?!api/|_next/|_proxy/|_static|_vercel|[\\w-]+\\.\\w+).*)",
//"/((?!api/|_next/|_proxy/|_static|_vercel|[\\w-]+\\.\\w+).*)",
"/s/:slug*",
],
};
6 changes: 4 additions & 2 deletions src/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import type { UserRole } from "@prisma/client";

import NextAuth from "next-auth";
import authConfig from "auth.config";

import { PrismaAdapter } from "@auth/prisma-adapter";

import { db } from "./db";

import { getUserById } from "./utils/user";
Expand Down Expand Up @@ -33,7 +35,7 @@ export const {
if (account?.provider !== "credentials") return true;

// Check if user exists:
const existingUser = await getUserById(user.id);
const existingUser = await getUserById(user.id!);

// Prevent sign in without email verification:
if (!existingUser?.emailVerified) return false;
Expand Down Expand Up @@ -65,7 +67,7 @@ export const {

if (session.user) {
session.user.name = token.name;
session.user.email = token.email;
session.user.email = token.email!;
session.user.isOAuth = token.isOAuth as boolean;
}

Expand Down

0 comments on commit cd74648

Please sign in to comment.