Environment:
Appwrite Version: 1.5.7
Framework: Next.js (latest)
Issue: In a Next.js app, getCurrentUserInfo redirects to an error page when a document is not found, even though it logs the error and returns null. This contrasts with getLoggedInUser, which handles similar errors correctly by only logging and returning null.
export const getCurrentUserInfo = async (id: string) => {
try {
const { databases } = await createDatabaseClient();
const db = await getDatabaseClient(databases);
const userInfo = await db.users.get(id);
if (!userInfo || userInfo.deleted) return null;
return userInfo;
} catch (error) {
console.error("Error:", error);
return null; // Unwanted redirect happens here
}
};
const Home = async () => {
const user = await getLoggedInUser();
const userInfo = await addUserInfoToDB(user);
return <div>{user && <Component user={user} />}</div>;
}
Behavior:
getCurrentUserInfo causes a redirect on errors.
getLoggedInUser functions correctly without redirects.
Question: How can I avoid these unwanted redirects while maintaining consistent error handling?
Any help or insights would be appreciated!
export async function getLoggedInUser() {
try {
const { account } = await createSessionClient()
return await account.get()
} catch (error) {
console.error(error)
return null
}
}
This login function works properly without redirecting to error page
Recommended threads
- CORS errors in Obsidian custom plugin
Hi, anyone here familiar with obsidian community plugins? In short: it's a local first note app which supports writing your own add-ons / plugin But I keep get...
- > AppwriteException: The requested servi...
When trying to read or write from my database I get the following error: > AppwriteException: The requested service is disabled. You can enable the service from...
- Courtesy limit reset for non-profit migr...
Hi Team! I'm the architect for a 501(c)(3) non-profit project (Aaria's Blue Elephant) and we just hit our Free plan Database Read limit (currently at 164%). Th...