
I have created an account with appwrite then logged it. both of them are working fine. but when i'm trying to get the user by using this method:
export const getAccount = async () => {
try {
const user = await account.get();
return user;
} catch (error: any) {
console.error("An error occurred while fetching user:", error);
}
};
it's not getting any user info. how can i fix this issue?

You're getting error?

If so, it could be that the user is not logged in

What error are you getting?

I am not getting any error. it's just not giving me the user info. here is my auth related code.
// Create APPWRITE ACCOUNT
export const createAccount = async (user: CreateAccountParams) => {
try {
const newUser = await account.create(
ID.unique(),
user.email,
user.password,
user.name,
);
await loginAccount({
email: user.email,
password: user.password
});
return parseStringify(newUser);
} catch (error: any) {
console.error("An error occurred while creating a new user:", error);
throw error; // Re-throw the error to handle it further up the call stack if needed
}
};
// Login APPWRITE ACCOUNT
export const loginAccount = async (user: LoginAccountParams) => {
try {
const loginUser = await account.createEmailPasswordSession(
user.email,
user.password
);
console.log(loginUser, "loginUser");
return parseStringify(loginUser);
} catch (error: any) {
console.error("An error occurred while fetching user:", error.message);
}
};
// GET APPWRITE Account
export const getAccount = async () => {
try {
const user = await account.get();
return user;
} catch (error: any) {
console.error("An error occurred while fetching user:", error);
}
};

I also check the cookies and localstorage. it's not saving my credential.

like secret key

Are you using some web framework like NextJS?

next js. yes

Then probably it's because of SSR. You will probably need to disble SSR or implement SSR login: https://appwrite.io/docs/tutorials/nextjs-ssr-auth/step-1

@D5Hey man, I have read the documentation and watched the tutorial from Appwrite, but I want to use the CSR method. I don’t want to change the whole config file to SSR. Is that possible?

Yes, I think you can use client in NextJS
Recommended threads
- Website shows just the HTML in safari
Hi y'all, I've been working on a project for a while but, for some reason it just shows the html in safari, It work perfectly fine in firefox and chrome, but sa...
- TableDB.getRow() response does not conta...
This is for Web/React sdk 20.0.0 The row was created via `TableDB.createRow(...)` and I can see it in the console with the relationships correctly set. In the c...
- Auth showing wrong numbers of users
I have 6 verified users but it shows 5 24 hours before I have 5 users that time its showing 4 users. Project ID: `68aed705001ef67ac979`
