-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathproxy.ts
More file actions
26 lines (22 loc) · 773 Bytes
/
proxy.ts
File metadata and controls
26 lines (22 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import {
convexAuthNextjsMiddleware,
createRouteMatcher,
nextjsMiddlewareRedirect,
} from "@convex-dev/auth/nextjs/server";
const isSignInPage = createRouteMatcher(["/signup", "/"]);
const isProtectedRoute = createRouteMatcher(["/home(.*)"]);
export default convexAuthNextjsMiddleware(
async (request, { convexAuth }) => {
const authenticated = await convexAuth.isAuthenticated();
if (isSignInPage(request) && authenticated) {
return nextjsMiddlewareRedirect(request, "/home");
}
if (isProtectedRoute(request) && !authenticated) {
return nextjsMiddlewareRedirect(request, "/");
}
},
{ cookieConfig: { maxAge: 60 * 60 * 24 * 30 } },
);
export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};