axios
This commit is contained in:
@ -1,23 +1,34 @@
|
||||
import React, { useState } from "react";
|
||||
import { TextField, Button, Box, Typography, Grid, Paper } from "@mui/material";
|
||||
import {Link, useNavigate } from 'react-router-dom';
|
||||
// import { fetchApi } from '../config/axios';
|
||||
|
||||
const LoginPage = () => {
|
||||
// State for email and password
|
||||
const [email, setEmail] = useState("");
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const navigate = useNavigate();
|
||||
|
||||
// Handle form submission
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
if (email && password) {
|
||||
// Handle login logic here, for example, API call
|
||||
console.log("Logged in with:", { email, password });
|
||||
localStorage.setItem('authToken', email)
|
||||
navigate('/');
|
||||
} else {
|
||||
alert("Please fill in both fields.");
|
||||
const handleSubmit = async (e) => {
|
||||
try {
|
||||
e.preventDefault();
|
||||
if (username && password) {
|
||||
// GET CREDIENTIAL
|
||||
// let user = await fetchApi('/api/login', 'POST', { username, password });
|
||||
// console.log(user);
|
||||
// if (user.data && user.data.data) {
|
||||
// let userLogin = user.data.data;
|
||||
|
||||
// }
|
||||
// document.cookie = `role=${role}`
|
||||
// localStorage.setItem('authToken', username)
|
||||
navigate('/');
|
||||
} else {
|
||||
alert("Please fill in both fields.");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
@ -39,9 +50,9 @@ const LoginPage = () => {
|
||||
label="Email"
|
||||
variant="outlined"
|
||||
fullWidth
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
type="email"
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
type="text"
|
||||
required
|
||||
/>
|
||||
</Box>
|
||||
|
||||
Reference in New Issue
Block a user