diff --git a/backend/controllers/questController.js b/backend/controllers/questController.js index ea62f37685..662b9dceb0 100644 --- a/backend/controllers/questController.js +++ b/backend/controllers/questController.js @@ -124,10 +124,10 @@ const showUserQuests = async (req, res) => { }); if (!filteredQuests.length) { - return res.status(404).json({ - success: false, + return res.status(200).json({ + success: true, response: [], - message: "No quests", + message: "No quests yet", }); } return res diff --git a/frontend/src/components/LoginForm.jsx b/frontend/src/components/LoginForm.jsx index 70371e82e6..3e4c4ecbb1 100644 --- a/frontend/src/components/LoginForm.jsx +++ b/frontend/src/components/LoginForm.jsx @@ -3,8 +3,10 @@ import { Link, useNavigate } from 'react-router-dom' import { useEffect, useState } from 'react' import { apiUrl } from '../../api' import { useUserStore } from '../stores/useUserStore' +import { useQuestStore } from '../stores/useQuestStore' export const LoginForm = () => { + const fetchQuests = useQuestStore((state) => state.fetchQuests) // State variables to store form input values // const [name, setName] = useState('') const [email, setEmail] = useState('') @@ -62,7 +64,7 @@ export const LoginForm = () => { login({ accessToken: data.accessToken, - userId: data.id, + userId: data.userID, email: email, name: data.name // check what the API actually returns here }) @@ -77,6 +79,8 @@ export const LoginForm = () => { // Clear the form inputs setEmail('') setPassword('') + + await fetchQuests(data.accessToken) // When signed up successfully -> redirect to profile page navigate('/') diff --git a/frontend/src/stores/useQuestStore.jsx b/frontend/src/stores/useQuestStore.jsx index 7396c2a2c7..9987c6fa9a 100644 --- a/frontend/src/stores/useQuestStore.jsx +++ b/frontend/src/stores/useQuestStore.jsx @@ -62,7 +62,7 @@ export const useQuestStore = create((set) => ({ if (!response.ok) return { success: false, error: data.message }; - set((state) => ({ quests: [...state.quests, data] })); + set((state) => ({ quests: [...state.quests, data.response || data] })) return { success: true }; } catch (error) { return { success: false, error: "Something went wrong" };