From cdd8c30c714d0fa096b27b3ef6384fc3ccc482fa Mon Sep 17 00:00:00 2001 From: Vivian Li Date: Thu, 21 Sep 2023 21:36:55 -0400 Subject: [PATCH] changed api url and added Header back --- frontend/src/App.js | 4 ++-- frontend/src/components/header.jsx | 4 +--- frontend/src/features/auth/authService.js | 6 +++++- frontend/src/features/auth/authSlice.js | 4 +++- frontend/src/features/goals/goalsService.js | 2 +- frontend/src/features/habits/habitsService.js | 2 +- frontend/src/pages/Habits.jsx | 5 +---- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/frontend/src/App.js b/frontend/src/App.js index cd42c54..45b83f7 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -5,14 +5,14 @@ import Login from './pages/Login' import Register from './pages/Register' import Habits from './pages/Habits' import Goals from './pages/Goals' -//import Header from './components/Header'; +import Header from './components/Header' function App() { return ( <>
- +
} /> } /> diff --git a/frontend/src/components/header.jsx b/frontend/src/components/header.jsx index 060f9c9..b97e488 100644 --- a/frontend/src/components/header.jsx +++ b/frontend/src/components/header.jsx @@ -4,7 +4,7 @@ import {Link, useNavigate} from 'react-router-dom' import {useSelector, useDispatch} from 'react-redux' import {logout, resetAuth} from '../features/auth/authSlice' import {resetGoals} from '../features/goals/goalsSlice' -import { resetHabits} from '../features/habits/habitsSlice' +import { resetHabits } from '../features/habits/habitsSlice' function Header() { @@ -44,8 +44,6 @@ function Header() { )} - -
) diff --git a/frontend/src/features/auth/authService.js b/frontend/src/features/auth/authService.js index 9d71cfd..7ed5c3d 100644 --- a/frontend/src/features/auth/authService.js +++ b/frontend/src/features/auth/authService.js @@ -1,6 +1,6 @@ import axios from 'axios' -const API_URL = process.env.SERVER_URL + '/api/users/' +const API_URL = 'https://caraibou-demo-api.onrender.com/api/users/' // Register user const register = async (userData) => { @@ -10,17 +10,21 @@ const register = async (userData) => { if(response.data) { localStorage.setItem('user', response.data) } + //console.log(typeof response.userData) return response.data } // Login user const login = async (userData) => { + console.log(API_URL) const response = await axios.post(API_URL + 'login', userData) if(response.data) { localStorage.setItem('user', JSON.stringify(response.data)) } + console.log(JSON.stringify(response.data)) + return response.data } diff --git a/frontend/src/features/auth/authSlice.js b/frontend/src/features/auth/authSlice.js index 548febe..45c064e 100644 --- a/frontend/src/features/auth/authSlice.js +++ b/frontend/src/features/auth/authSlice.js @@ -1,7 +1,9 @@ import {createSlice, createAsyncThunk} from '@reduxjs/toolkit' import authService from './authService' -const user = localStorage.getItem('user') +//console.log(localStorage.getItem('user')) +var user = JSON.parse(localStorage.getItem('user')) + const initialState = { user: user ? user : null, diff --git a/frontend/src/features/goals/goalsService.js b/frontend/src/features/goals/goalsService.js index ad22cdc..098e22d 100644 --- a/frontend/src/features/goals/goalsService.js +++ b/frontend/src/features/goals/goalsService.js @@ -1,6 +1,6 @@ import axios from 'axios' -const API_URL = process.env.SERVER_URL + '/api/goals/' +const API_URL = 'https://caraibou-demo-api.onrender.com/api/goals/' // submit goals diff --git a/frontend/src/features/habits/habitsService.js b/frontend/src/features/habits/habitsService.js index e5506d1..25027cf 100644 --- a/frontend/src/features/habits/habitsService.js +++ b/frontend/src/features/habits/habitsService.js @@ -1,6 +1,6 @@ import axios from 'axios' -const API_URL = process.env.SERVER_URL + '/api/habits/' +const API_URL = 'https://caraibou-demo-api.onrender.com/api/habits/' // submit habits diff --git a/frontend/src/pages/Habits.jsx b/frontend/src/pages/Habits.jsx index 7c934b4..4ac0b83 100644 --- a/frontend/src/pages/Habits.jsx +++ b/frontend/src/pages/Habits.jsx @@ -127,10 +127,7 @@ function Habits() {
- - - - + ) }