mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-05-04 04:33:10 +00:00
Initial Commit
This commit is contained in:
commit
f3e2f01bd7
150 changed files with 13612 additions and 0 deletions
34
middleware.ts
Normal file
34
middleware.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { authMiddleware, redirectToSignIn } from "@clerk/nextjs";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
// This example protects all routes including api/trpc routes
|
||||
// Please edit this to allow other routes to be public as needed.
|
||||
// See https://clerk.com/docs/references/nextjs/auth-middleware for more information about configuring your Middleware
|
||||
export default authMiddleware({
|
||||
publicRoutes: ["/", "/api/webhook"],
|
||||
afterAuth(auth, req) {
|
||||
if (auth.userId && auth.isPublicRoute) {
|
||||
let path = "/select-org";
|
||||
|
||||
if (auth.orgId) {
|
||||
path = `/organization/${auth.orgId}`;
|
||||
}
|
||||
|
||||
const orgSelection = new URL(path, req.url);
|
||||
return NextResponse.redirect(orgSelection);
|
||||
}
|
||||
|
||||
if (!auth.userId && !auth.isPublicRoute) {
|
||||
return redirectToSignIn({ returnBackUrl: req.url });
|
||||
}
|
||||
|
||||
if (auth.userId && !auth.orgId && req.nextUrl.pathname !== "/select-org") {
|
||||
const orgSelection = new URL("/select-org", req.url);
|
||||
return NextResponse.redirect(orgSelection);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const config = {
|
||||
matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/", "/(api|trpc)(.*)"],
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue