I'm not sure if this is a problem with my application or with appWrite, but I suddenly can't get the status and I don't know why. This problem is a little hard to explain.
For example, const { account } = createSessionClient(sessionSecret); When the value of cookieSession is correct, it will be in a state of loading forever.
Detailed explanation: First of all this happened out of the blue, I swear I didn't change any code. I just said that when the session secret value is correct it won't give me any response. But when the session secret is wrong appwrite will throw an error, then I will judge that the user is not valid. But the problem is that if the user is logged in and has valid credentials it will just keep loading, I will proceed to the next step.
[URGENT] Suddenly unable to stay logged in.
export async function getCurrentUser(): Promise<User | null> { try { const cookieSession = await getCookieSession();
if (!cookieSession) return null;
const { account } = createSessionClient(cookieSession);
const { databases } = createAdminClient();
const currentUser = await account.get();
const users = await databases.listDocuments(
process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID!,
process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_USERS!,
[Query.equal("userId", currentUser.$id), Query.limit(1)],
);
console.log({ users });
if (users.total === 0) return null;
const user = users.documents[0] as UserDetails;
const onboardings = await databases.listDocuments(
process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID!,
process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_ONBOARDING!,
[Query.equal("userRefId", user.$id), Query.limit(1)],
);
const notifications = await getNotifications();
const createdOrganizations = await Promise.all(
(
(
await databases.listDocuments(
process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID!,
process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_ORGANIZATIONS!,
[Query.equal("creatorRefId", user.$id)],
)
).documents as Organization[]
).map(async (organization) => {
const members = (
await databases.listDocuments(
process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID!,
process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_MEMBERS!,
[Query.equal("organizationRefId", organization.$id)],
)
).documents;
return { ...organization, members };
}),
);
const joinedOrganizations = await getJoinedOrganizations( user.joinedOrganizationsRefId, );
return {
...currentUser,
details: {
...user,
notifications,
joinedOrganizations,
onboarding: onboardings.documents[0],
createdOrganizations: createdOrganizations,
},
} as unknown as User;
} catch (error) { console.log("Failed to get current user", error); return null; } }
The above is the complete code
You can see that I put a console.log
It keeps outputting repeatedly, which proves that getCurrentUser is being called repeatedly.
Recommended threads
- My cloud functions failing 3 days ago (P...
Hi, My cloud function using python has been failing for 3 days, I didn't push any new deployments... Its something to do with it not recognising the entrypoi...
- Function was working: Failed to load ent...
I had a Bun function deployed two months ago working until 2 days ago on a daily basis, now I'm getting: Failed to load entrypoint, file src/main.js does not ex...
- Migration Help
I have a small project which I have started using Appwrite cloud and now I want to self host Appwrite and migrate the data. I'm getting this error everytime I ...