Spaces:
Sleeping
Sleeping
Tristan Yu commited on
Commit ·
cca18d7
1
Parent(s): 8417b9f
Fix login to use api service instead of fetch with relative URL
Browse files- src/pages/Login.tsx +5 -7
src/pages/Login.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import React, { useState } from 'react';
|
| 2 |
import { useNavigate } from 'react-router-dom';
|
|
|
|
| 3 |
|
| 4 |
// Pre-loaded user details
|
| 5 |
const PREDEFINED_USERS = {
|
|
@@ -33,13 +34,10 @@ const Login: React.FC = () => {
|
|
| 33 |
setError('');
|
| 34 |
|
| 35 |
try {
|
| 36 |
-
//
|
| 37 |
-
const response = await
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
body: JSON.stringify({ email })
|
| 41 |
-
});
|
| 42 |
-
const data = await response.json();
|
| 43 |
if (data.success) {
|
| 44 |
localStorage.setItem('token', data.token);
|
| 45 |
localStorage.setItem('user', JSON.stringify(data.user));
|
|
|
|
| 1 |
import React, { useState } from 'react';
|
| 2 |
import { useNavigate } from 'react-router-dom';
|
| 3 |
+
import { api } from '../services/api';
|
| 4 |
|
| 5 |
// Pre-loaded user details
|
| 6 |
const PREDEFINED_USERS = {
|
|
|
|
| 34 |
setError('');
|
| 35 |
|
| 36 |
try {
|
| 37 |
+
// Use the api service to make the request to the backend
|
| 38 |
+
const response = await api.post('/auth/login', { email });
|
| 39 |
+
const data = response.data;
|
| 40 |
+
|
|
|
|
|
|
|
|
|
|
| 41 |
if (data.success) {
|
| 42 |
localStorage.setItem('token', data.token);
|
| 43 |
localStorage.setItem('user', JSON.stringify(data.user));
|