Rank 1: Thread
I am trying to implement the NextJS Todo Demo app with Appwrite. But, I am using a XYZ app to authenticate users.
Now once the user is checked as isAuthorized, based on its userId, I want to create a jwt token and sign it for the Appwrite session so that I will be able to fetch ToDo documents associated with this userId from Appwrite.
I just want someone to check my code and guide me to do it in a correct way.
I am currently using getServerSideProps.
export const getServerSideProps = async (context) => { const loginProps = await getAuthenticatedUserFromSession( context.req, context.res );
if (loginProps.isAuthorized) { const appwrite = getAppwrite(loginProps.userID); const database = new Databases(appwrite, process.env.APPWRITE_DATABASE_ID); const { data } = await database.listDocuments( process.env.APPWRITE_DATABASE_ID, process.env.APPWRITE_COLLECTION_ID, )
return { props: { isAuthorized: loginProps.isAuthorized ?? false, userID: loginProps.userID ?? "", initialTodos: data ?? [], }, }; } else { return { props: { isAuthorized: loginProps.isAuthorized ?? false, userID: loginProps.userID ?? "", }, }; }};