TypeScript
// function to get session.
export async function auth() {
try {
const cookieStore = await cookies()
const sessionCookie = cookieStore.get("appwrite-session")
if (!sessionCookie) {
log.info("No session cookie found")
return null
}
const { account } = await createSessionClient()
return await account.get()
} catch (error) {
console.error("Error during authentication:", error)
return null
}
}
TL;DR
Developers are trying to access session inside 'middleware.ts' but facing difficulties. They mention that the application works fine on 'localhost' and 'self-hosted' setups. The provided code snippet shows an 'auth' function that tries to retrieve a session cookie but encounters issues.
Solution: Check if the cookieStore.get("appwrite-session") is returning the session correctly. Make sure that the session is properly set up and accessible within the middleware. Double-check the middleware configuration and ensure the cookie is being passed correctly for session retrieval.locallhost, and also self hosted woking just fine
Recommended threads
- "Restore project" button fails: "Invalid...
In the dashboard, it clicking "Restore project" fails. The request sent to `PATCH https://cloud.appwrite.io/v1/projects/:project_id` with payload `{status: "act...
- how to access the value of account statu...
- Redirect from clicking team invite link ...
Hi all! Pretty new to app development in general so this might be something more generic than appwrite, but I've found (after reading the docs for the Teams API...