Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code-clean up #37

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions pages/auth/api.js

This file was deleted.

33 changes: 21 additions & 12 deletions pages/auth/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useState } from 'react';
import Box from "@mui/material/Box";
import Link from "next/link";
import { useRouter } from 'next/router';
import { loginUser } from './api';

function Login() {
const [username, setUsername] = useState('');
Expand All @@ -15,16 +14,26 @@ function Login() {
alert('Please fill in all the required fields.');
return;
}

const { success, data, error } = await loginUser(username, password);

if (success) {
console.log('Login successful');
alert('Login successful.');
router.push('/');
} else {
console.log('Login failed:', error);
alert(`Login failed. ${error}`);
try {
const response = await fetch('http://41.89.92.186:8000/users/login/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ username, password }),
});

if (response.ok) {
console.log('Login successful');
alert('Login successful.');
router.push('/');
} else {
console.log('Login failed');
alert('Login failed. Please check your credentials and try again.');
}
} catch (error) {
console.error('Error during login:', error);
alert('An unexpected error occurred. Please try again later.');
}
};

Expand Down Expand Up @@ -163,4 +172,4 @@ function Login() {
);
}

export default Login;
export default Login;