Skip to content

Commit f228cb3

Browse files
committed
Implemented the changes requested
1 parent 07879cb commit f228cb3

File tree

7 files changed

+65
-17
lines changed

7 files changed

+65
-17
lines changed

frontend/src/App.tsx

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,62 @@ function App() {
2626

2727
//Auto login if user has already logged in
2828
useEffect(() => {
29-
supabase.auth.getSession().then(({ data ,error }) => {
29+
supabase.auth.getSession().then(({ data, error }) => {
3030
if (error) {
3131
toast.error('User Login Failed');
32-
console.error('Error checking session:'+ error);
32+
console.error('Error checking session:', error);
3333
return;
3434
}
35-
if (data.session) {
36-
setIsAuthenticated(true);
37-
}
35+
setIsAuthenticated(!!data.session);
3836
});
37+
38+
const { data: subscription } = supabase.auth.onAuthStateChange(
39+
(event, session) => {
40+
console.log("Auth event:", event, session);
41+
switch(event){
42+
case "SIGNED_IN":
43+
setIsAuthenticated(true);
44+
toast.success("Signed in!");
45+
break;
46+
47+
case "SIGNED_OUT":
48+
setIsAuthenticated(false);
49+
setActivePage("landing");
50+
setRepoData(null);
51+
toast.success("Signed out!");
52+
break;
53+
54+
case "PASSWORD_RECOVERY":
55+
toast("Check your email to reset your password.");
56+
break;
57+
case "TOKEN_REFRESHED":
58+
console.log("Session refreshed");
59+
break;
60+
case "USER_UPDATED":
61+
console.log("User updated", session?.user);
62+
break;
63+
}
64+
}
65+
);
66+
67+
return () => {
68+
subscription.subscription.unsubscribe();
69+
};
3970
}, []);
4071

72+
4173
const handleLogin = () => {
4274
setIsAuthenticated(true);
4375
};
4476

45-
const handleLogout = () => {
77+
const handleLogout = async () => {
78+
const { error } = await supabase.auth.signOut();
79+
if (error) {
80+
toast.error('Logout failed');
81+
console.error('Error during logout:', error);
82+
return;
83+
}
84+
toast.success('Signed out!');
4685
setIsAuthenticated(false);
4786
setActivePage('landing');
4887
setRepoData(null);
@@ -67,7 +106,7 @@ function App() {
67106
case 'settings':
68107
return <SettingsPage />;
69108
case 'profile':
70-
return <ProfilePage />;
109+
return <ProfilePage onSignOut={handleLogout} />;
71110
default:
72111
return <Dashboard repoData={repoData} />;
73112
}

frontend/src/components/pages/ForgotPasswrdPage.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState, ReactNode, FormEvent } from "react";
22
import { motion } from "framer-motion";
33
import { useNavigate } from 'react-router-dom';
4-
import { toast, Toaster } from "react-hot-toast";
4+
import { toast} from "react-hot-toast";
55
import { supabase } from "../../lib/supabaseClient";
66

77

@@ -71,7 +71,6 @@ export default function ForgotPasswrdPage() {
7171
<AuthLayout>
7272

7373
<div className="bg-gray-900 p-8 rounded-xl border border-gray-800">
74-
<Toaster position="top-right" />
7574
{!mailPage ? (
7675
<>
7776
<motion.div
@@ -115,7 +114,7 @@ export default function ForgotPasswrdPage() {
115114
<p className="text-center text-gray-400 text-sm">
116115
<button
117116
type="button"
118-
onClick={() => navigate('/signup')}
117+
onClick={() => navigate('/login')}
119118
className="text-gray-400 hover:text-gray-300 font-medium"
120119
>
121120
Back to Sign In

frontend/src/components/pages/ProfilePage.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useState } from 'react';
22
import { motion } from 'framer-motion';
33
import { toast } from 'react-hot-toast';
4-
import { User, Mail, Building, Globe, Github, Twitter, Edit, Camera, Save } from 'lucide-react';
4+
import { User, Mail, Building, Globe, Github, Twitter, Edit, Camera, Save, DoorClosed } from 'lucide-react';
55

6-
const ProfilePage = () => {
6+
const ProfilePage = ({onSignOut}:{onSignOut:()=>void}) => {
77
const [isEditing, setIsEditing] = useState(false);
88
const [profile, setProfile] = useState({
99
name: 'Sarah Chen',
@@ -179,7 +179,19 @@ const ProfilePage = () => {
179179
className="w-full bg-gray-800 rounded-lg p-3 text-white focus:outline-none focus:ring-2 focus:ring-green-500 disabled:opacity-50"
180180
/>
181181
</div>
182-
182+
<div className="mt-8 flex justify-end">
183+
<motion.button
184+
whileHover={{ scale: 1.05 }}
185+
whileTap={{ scale: 0.95 }}
186+
onClick={() => {
187+
onSignOut();
188+
}}
189+
className="px-4 py-2 bg-red-500 hover:bg-red-600 rounded-lg transition-colors flex items-center"
190+
>
191+
<DoorClosed size={18} className="mr-2" />
192+
Sign Out
193+
</motion.button>
194+
</div>
183195
{isEditing && (
184196
<div className="mt-8 flex justify-end space-x-4">
185197
<motion.button

frontend/src/components/pages/ResetPasswordPage.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useState, useEffect } from "react";
22
import type { ReactNode, FormEvent } from "react";
33
import { motion } from "framer-motion";
44
import { useNavigate } from 'react-router-dom';
5-
import { toast, Toaster } from "react-hot-toast";
5+
import { toast} from "react-hot-toast";
66
import { supabase } from "../../lib/supabaseClient";
77
import {
88
Settings,
@@ -137,7 +137,6 @@ export default function ResetPasswordPage() {
137137
return (
138138
<AuthLayout>
139139
<div className="bg-gray-900 p-8 rounded-xl border border-gray-800">
140-
<Toaster position="top-right" />
141140
<>
142141
<motion.div
143142
initial={{ opacity: 0 }}

frontend/src/components/pages/SignUpPage.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState, ReactNode, FormEvent } from "react";
22
import { motion } from "framer-motion";
33
import { useNavigate } from 'react-router-dom';
4-
import { toast, Toaster } from "react-hot-toast";
4+
import { toast } from "react-hot-toast";
55
import { supabase } from "../../lib/supabaseClient";
66

77

@@ -112,7 +112,6 @@ export default function SignUpPage() {
112112
return (
113113
<AuthLayout>
114114
<div className="bg-gray-900 p-8 rounded-xl border border-gray-800">
115-
<Toaster position="top-right" />
116115
{!mailPage ? (
117116
<>
118117
<motion.div

frontend/vite.config.ts.timestamp-1756982444425-c72798bad4dac.mjs

Whitespace-only changes.

0 commit comments

Comments
 (0)