Skip to content

Commit

Permalink
fix(platform): middlware
Browse files Browse the repository at this point in the history
  • Loading branch information
not-ani committed Aug 20, 2024
1 parent e0ada23 commit 9d62e20
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions apps/nextjs/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
export { auth as middleware } from "@amaxa/auth";
import { NextResponse } from "next/server";

// Or like this if you need to do something here.
// export default auth((req) => {
// console.log(req.auth) // { session: { user: { ... } } }
// })
import { auth } from "@amaxa/auth";

export default auth((req) => {
const { nextUrl } = req;

const isLoggedIn = !!req.auth;

if (!isLoggedIn && nextUrl.pathname !== "/sign-in") {
return NextResponse.redirect(new URL("/sign-in", nextUrl));
}
});

// Read more: https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
export const config = {
Expand Down

0 comments on commit 9d62e20

Please sign in to comment.