diff --git a/backend/controllers/auth.controller.js b/backend/controllers/auth.controller.js index 1912ddc..b64acf5 100644 --- a/backend/controllers/auth.controller.js +++ b/backend/controllers/auth.controller.js @@ -144,6 +144,33 @@ export const updateProfile = async (req, res) => { } }; +// NEW: Remove profile picture — sets profile_pic to null +export const removeProfilePic = async (req, res) => { + try { + if (!req.user) { + return res.status(401).json({ message: "Unauthorized" }); + } + + const userId = req.user.id; + + const { data, error } = await supabase + .from('profiles') + .update({ profile_pic: null }) + .eq('id', userId) + .select() + .single(); + + if (error) { + return res.status(400).json({ message: error.message }); + } + + res.status(200).json(data); + } catch (error) { + console.error("Error in removeProfilePic:", error); + res.status(500).json({ message: "Server error" }); + } +}; + export const checkAuth = async (req, res) => { try { // Get profile data diff --git a/backend/routes/auth.route.js b/backend/routes/auth.route.js index 252b1ee..5a6fe80 100644 --- a/backend/routes/auth.route.js +++ b/backend/routes/auth.route.js @@ -1,24 +1,26 @@ -import express from 'express'; -import { - signup, - login, - logout, - updateProfile, - checkAuth, - getProfile -} from '../controllers/auth.controller.js'; -import { protectRoute } from '../middleware/auth.middleware.js'; - -const router = express.Router(); - -// Public routes -router.post('/signup', signup); -router.post('/login', login); -router.post('/logout', logout); - -// Protected routes -router.get('/check', protectRoute, checkAuth); -router.put('/update-profile', protectRoute, updateProfile); -router.get('/profile/:userId', protectRoute, getProfile); - +import express from 'express'; +import { + signup, + login, + logout, + updateProfile, + removeProfilePic, + checkAuth, + getProfile +} from '../controllers/auth.controller.js'; +import { protectRoute } from '../middleware/auth.middleware.js'; + +const router = express.Router(); + +// Public routes +router.post('/signup', signup); +router.post('/login', login); +router.post('/logout', logout); + +// Protected routes +router.get('/check', protectRoute, checkAuth); +router.put('/update-profile', protectRoute, updateProfile); +router.delete('/remove-profile-pic', protectRoute, removeProfilePic); // NEW +router.get('/profile/:userId', protectRoute, getProfile); + export default router; \ No newline at end of file diff --git a/frontend/src/api/auth.api.js b/frontend/src/api/auth.api.js index f9c0f0d..7d6023a 100644 --- a/frontend/src/api/auth.api.js +++ b/frontend/src/api/auth.api.js @@ -1,40 +1,46 @@ -import api from './axios'; - -export const authAPI = { - signup: async (data) => { - const response = await api.post('/auth/signup', data); - return response.data; - }, - - login: async (credentials) => { - const response = await api.post('/auth/login', credentials); - if (response.data.session?.access_token) { - localStorage.setItem('token', response.data.session.access_token); - localStorage.setItem('user', JSON.stringify(response.data.user)); - localStorage.setItem('profile', JSON.stringify(response.data.profile)); - } - return response.data; - }, - - logout: async () => { - await api.post('/auth/logout'); - localStorage.removeItem('token'); - localStorage.removeItem('user'); - localStorage.removeItem('profile'); - }, - - checkAuth: async () => { - const response = await api.get('/auth/check'); - return response.data; - }, - - updateProfile: async (profilePic) => { - const response = await api.put('/auth/update-profile', { profilePic }); - return response.data; - }, - - getProfile: async (userId) => { - const response = await api.get(`/auth/profile/${userId}`); - return response.data; - }, +import api from './axios'; + +export const authAPI = { + signup: async (data) => { + const response = await api.post('/auth/signup', data); + return response.data; + }, + + login: async (credentials) => { + const response = await api.post('/auth/login', credentials); + if (response.data.session?.access_token) { + localStorage.setItem('token', response.data.session.access_token); + localStorage.setItem('user', JSON.stringify(response.data.user)); + localStorage.setItem('profile', JSON.stringify(response.data.profile)); + } + return response.data; + }, + + logout: async () => { + await api.post('/auth/logout'); + localStorage.removeItem('token'); + localStorage.removeItem('user'); + localStorage.removeItem('profile'); + }, + + checkAuth: async () => { + const response = await api.get('/auth/check'); + return response.data; + }, + + updateProfile: async (profilePic) => { + const response = await api.put('/auth/update-profile', { profilePic }); + return response.data; + }, + + // NEW: remove profile picture + removeProfilePic: async () => { + const response = await api.delete('/auth/remove-profile-pic'); + return response.data; + }, + + getProfile: async (userId) => { + const response = await api.get(`/auth/profile/${userId}`); + return response.data; + }, }; \ No newline at end of file diff --git a/frontend/src/components/auth/LoginForm.jsx b/frontend/src/components/auth/LoginForm.jsx index cbed1b7..5c69b98 100644 --- a/frontend/src/components/auth/LoginForm.jsx +++ b/frontend/src/components/auth/LoginForm.jsx @@ -30,10 +30,6 @@ const LoginForm = () => { } }; - const handleGoogleSignIn = () => { - alert('Google Sign-In coming soon!'); - }; - return (