Skip to content

Commit

Permalink
Added middleware.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
SujithThirumalaisamy committed Aug 21, 2024
1 parent bcbdc1e commit 81d7e7c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
23 changes: 23 additions & 0 deletions src/app/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { withAuth } from 'next-auth/middleware';
import { NextResponse } from 'next/server';

export const config = {
matcher: ['/courses/:path*'],
};

export default withAuth(async (req) => {
if (process.env.LOCAL_CMS_PROVIDER) return;

const token = req.nextauth.token;
if (!token) {
return NextResponse.redirect(new URL('/invalidsession', req.url));
}
const user = await fetch(
`${process.env.NEXT_PUBLIC_BASE_URL_LOCAL}/api/user?token=${token.jwtToken}`,
);

const json = await user.json();
if (!json.user) {
return NextResponse.redirect(new URL('/invalidsession', req.url));
}
});
6 changes: 3 additions & 3 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ export function ToggleButton({
className="flex flex-col items-center justify-center"
>
<span
className={`h - 0.5 w - 6 - sm bg - black - all duration - 300 ease - out dark: bg - white block rounded transition ${!sidebarOpen ? 'translate-y-1 rotate-45' : '-translate-y-0.5'} `}
className={`h - 0.5 w 6 sm bg black all duration 300 ease out dark: white block rounded transition ${!sidebarOpen ? 'translate-y-1 rotate-45' : '-translate-y-0.5'} `}
></span>
<span
className={`my - 0.5 h - 0.5 w - 6 - sm bg - black - all duration - 300 ease - out dark: bg - white block rounded transition ${
className={`my - 0.5 h w 6 sm bg black all duration 300 ease out dark: white block rounded transition ${
!sidebarOpen ? 'opacity-0' : 'opacity-100'
} `}
></span>
<span
className={`h - 0.5 w - 6 - sm bg - black - all duration - 300 ease - out dark: bg - white block rounded transition ${
className={`h - 0.5 w 6 sm bg black all duration 300 ease out dark: white block rounded transition ${
!sidebarOpen ? '-translate-y-1 -rotate-45' : 'translate-y-0.5'
} `}
></span>
Expand Down
10 changes: 5 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"incremental": true,
"plugins": [
{
"name": "next"
}
"name": "next",
},
],
"paths": {
"@/*": ["./src/*"],
"@public/*": ["./public/*"]
}
"@public/*": ["./public/*"],
},
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
"exclude": ["node_modules"],
}

0 comments on commit 81d7e7c

Please sign in to comment.