Skip to content

Commit 712f580

Browse files
Merge pull request #96 from hanuchaudhary/middleware
2 parents 63a4477 + 8665d39 commit 712f580

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

app/dashboard/profile/page.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function DashboardContent({ authUser }: any) {
1313
return (
1414
<main className="container mx-auto space-y-6">
1515
<h1 className="text-3xl font-bold">Welcome, {authUser?.fullName}</h1>
16-
<Card>
16+
<Card className="bg-secondary">
1717
<CardHeader>
1818
<CardTitle>Your Profile</CardTitle>
1919
</CardHeader>
@@ -75,7 +75,7 @@ export default function Dashboard() {
7575
<>
7676
<DashboardContent authUser={authUser} />
7777
{leetcodeStats && (
78-
<div className="container mx-auto bg-neutral-800 rounded-lg p-3 mt-6">
78+
<div className="container mx-auto bg-secondary rounded-lg p-3 mt-6">
7979
<h2 className="text-xl font-semibold mb-4">Your LeetCode Progress</h2>
8080
<div className="max-w-xl">
8181
<Bar data={chartData} />

components/dashboardComponents/AppSidebar.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Button } from "@/components/ui/button";
1616
import { cn } from "@/lib/utils";
1717
import { SidebarData } from "@/data/SidebarData";
1818
import { supabase } from "@/lib/supabaseClient";
19+
import { signout } from "@/app/actions/action";
1920

2021
export function AppSidebar() {
2122
const { setTheme, theme } = useTheme();
@@ -24,13 +25,11 @@ export function AppSidebar() {
2425
const [isCollapsed, setIsCollapsed] = React.useState(false);
2526
const handleLogout = async () => {
2627
try {
27-
const { error } = await supabase.auth.signOut();
28-
if (error) throw error;
28+
signout();
2929
router.push('/auth/signin');
3030
} catch (error) {
3131
console.error("Sign out error:", error);
32-
}
33-
// Fix the Logout functionality, something is wrong here, It keeps throwing a 307 error on logout,and the user is not redirected to the login page
32+
}
3433
};
3534

3635
return (

package-lock.json

+11-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"@radix-ui/react-tooltip": "^1.1.6",
2424
"@supabase/ssr": "^0.5.2",
2525
"@types/bcryptjs": "^2.4.6",
26-
"@types/express": "^5.0.0",
2726
"@types/react-chartjs-2": "^2.0.2",
2827
"axios": "^1.7.9",
2928
"bcryptjs": "^2.4.3",
@@ -49,6 +48,7 @@
4948
"@eslint/eslintrc": "^3",
5049
"@supabase/auth-helpers-nextjs": "^0.10.0",
5150
"@supabase/supabase-js": "^2.47.11",
51+
"@types/express": "^5.0.0",
5252
"@types/node": "^20",
5353
"@types/react": "^19",
5454
"@types/react-dom": "^19",

utils/supabase/middleware.ts

+9
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ export async function updateSession(request: NextRequest) {
4747
// return NextResponse.redirect(url)
4848
// }
4949

50+
//if no user and user try to hit any route other than /auth/signin or /auth/signup or /, redirect to /auth/signin
51+
if (!user && !request.nextUrl.pathname.startsWith('/auth/signin') && !request.nextUrl.pathname.startsWith('/auth/signup') && request.nextUrl.pathname !== '/') {
52+
const url = request.nextUrl.clone()
53+
url.pathname = '/auth/signin'
54+
return NextResponse.redirect(url)
55+
}
56+
57+
58+
5059
if (
5160
user &&
5261
(request.nextUrl.pathname === '/' ||

0 commit comments

Comments
 (0)