Open Rope-a-dope opened 1 month ago
On buy page, click on the buy button will not redirect to stripe page unless I refresh the page and then click buy.
Second problem: In the auth-edge.ts file, I have warnings, I have to use ! and as string/boolean to get rid of it.
import { NextAuthConfig } from "next-auth"; import prisma from "./db"; export const nextAuthEdgeConfig = { pages: { signIn: "/login", }, callbacks: { authorized: ({ auth, request }) => { // runs on every request with middleware const isLoggedIn = Boolean(auth?.user); const isTryingToAccessApp = request.nextUrl.pathname.includes("/app"); if (!isLoggedIn && isTryingToAccessApp) { return false; } if (isLoggedIn && isTryingToAccessApp && !auth?.user.hasAccess) { return Response.redirect(new URL("/payment", request.nextUrl)); } if (isLoggedIn && isTryingToAccessApp && auth?.user.hasAccess) { return true; } if ( isLoggedIn && (request.nextUrl.pathname.includes("/login") || request.nextUrl.pathname.includes("/signup")) && auth?.user.hasAccess ) { return Response.redirect(new URL("/app/dashboard", request.nextUrl)); } if (isLoggedIn && !isTryingToAccessApp && !auth?.user.hasAccess) { if ( request.nextUrl.pathname.includes("/login") || request.nextUrl.pathname.includes("/signup") ) { return Response.redirect(new URL("/payment", request.nextUrl)); } return true; } if (!isLoggedIn && !isTryingToAccessApp) { return true; } return false; }, jwt: async ({ token, user, trigger }) => { if (user) { // on sign in token.userId = user.id; token.email = user.email; token.hasAccess = user.hasAccess; } if (trigger === "update") { // on every request const userFromDb = await prisma.user.findUnique({ where: { email: token.email!, }, }); if (userFromDb) { token.hasAccess = userFromDb.hasAccess; } } return token; }, session: ({ session, token }) => { session.user.id = token.userId as string; session.user.hasAccess = token.hasAccess as boolean; return session; }, }, providers: [], } satisfies NextAuthConfig;
On buy page, click on the buy button will not redirect to stripe page unless I refresh the page and then click buy.
Second problem: In the auth-edge.ts file, I have warnings, I have to use ! and as string/boolean to get rid of it.![image](https://github.com/ByteGrad/Professional-React-and-Next.js-Course/assets/38259673/3a397d4e-9a61-44b2-ae5c-90b38c1c6315)