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
- Active Running Project Deletion Alert Em...
Hi , I received an email alert from Appwrite today stating “your project will be deleted within 14 days if no action is taken,” though I have been actively usin...
- Project restoration button in console
The project restore button in console is taking no effect, i have tried several times and still nothing, it gives same popup if i reload
- SGP region: console returns 401 for all ...
Cloud console cannot open my projects in the Singapore (SGP) region. All console requests return HTTP 401, plus a 503 on analytics.appwrite.io. - Account email...