Skip to content

Commit 803bdf4

Browse files
Add logging for authentication process; enhance error handling and user feedback
1 parent b2d9bce commit 803bdf4

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/appwrite/auth.service.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,24 @@ export class AuthService{
3131
async login({email, password}){
3232
// eslint-disable-next-line no-useless-catch
3333
try {
34-
await this.account.createEmailPasswordSession(email,password);
34+
console.log("Creating email/password session for:", email);
35+
const session = await this.account.createEmailPasswordSession(email, password);
36+
console.log("Session created:", session);
37+
return session;
3538
} catch (error) {
3639
throw error
3740
}
3841
}
3942

4043
async getCurrentUser(){
4144
try {
42-
return await this.account.get();
45+
console.log("Calling getCurrentUser");
46+
const user = await this.account.get();
47+
console.log("getCurrentUser result:", user);
48+
return user;
4349
} catch (error) {
4450
console.log("Appwrite service :: getCurrentUser :: error", error);
51+
throw error;
4552
}
4653
// return null;//in case the account get method fails to return an error;
4754
}

src/components/Login.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ function Login() {
1616
const login = async(data) => {
1717
setError("") //clear all error on submission start
1818
try {
19+
console.log("Attempting to log in with data:", data);
1920
const session = await authService.login(data)
2021
console.log("session done")
2122
if(session){
23+
console.log("Fetching current user");
2224
const userData = await authService.getCurrentUser()
23-
console.log(userData)
25+
console.log("Inside session", userData)
2426
if(userData){
2527
dispatch(authLogin(userData));
2628
}
@@ -35,7 +37,7 @@ function Login() {
3537
navigate('/'); // Navigate to home page if user is logged in
3638
}
3739
}, [userData, navigate]);
38-
40+
3941
return (
4042
<div
4143
className='flex items-center justify-center w-full pt-5 pb-5'

0 commit comments

Comments
 (0)