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
- Weird permission failure
when creating an account I use following methods: ``` Future<void> register(String email, String password, String username) async { final user = await accoun...
- Appwrite Storage error 503s for automate...
I'm facing error 503s from Appwrite after about 5-6 seconds of making AI requests from my tool with images and files above 20MB (=> not inline base64 used, but ...
- Flutter Android oAuth is no more working
I currently don't get the oAuth login to work in flutter android. it works on ios and on web. but when try to use it on Android, i get to the point where the ca...