Unwanted Error Page Redirects in Next.js with Appwrite on "Document Not Found"
Unanswered
Prairie yellowjacket posted this in #help-forum
Prairie yellowjacketOP
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.
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? I don't want the redirection to error page happening
Any help or insights would be appreciated!
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? I don't want the redirection to error page happening
Any help or insights would be appreciated!
1 Reply
Prairie yellowjacketOP
using
"next": "14.2.3",