MCPcopy Create free account
hub / github.com/code100x/cms / withAuth

Function withAuth

src/middleware.ts:59–76  ·  view source on GitHub ↗
(req: NextRequestWithAuth)

Source from the content-addressed store, hash-verified

57};
58
59const withAuth = async (req: NextRequestWithAuth) => {
60 if (process.env.LOCAL_CMS_PROVIDER) return;
61
62 const token = await getToken({ req });
63
64 if (!token) {
65 return NextResponse.redirect(new URL('/invalidsession', req.url));
66 }
67
68 const user = await fetch(
69 `${process.env.NEXT_PUBLIC_BASE_URL_LOCAL}/api/user?token=${token.jwtToken}`,
70 );
71
72 const json = await user.json();
73 if (!json.user) {
74 return NextResponse.redirect(new URL('/invalidsession', req.url));
75 }
76};
77
78export async function middleware(req: NextRequestWithAuth) {
79 const { pathname } = req.nextUrl;

Callers 1

middlewareFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected