Hi there,
I'm using the client sdk to authenticate the user within my nextjs frontend. I also need to access the user object, so I also use the server sdk. I followed these two guides to set it up:
- https://appwrite.io/docs/tutorials/nextjs-ssr-auth/step-3
- https://appwrite.io/blog/post/introducing-support-for-server-side-rendering
I use the OTP function for authentication (the one, where the user gets a one time password send via mail). I'm still having trouble to create a server session next to the client session.
I use this code:
app/page/login/page.tsx
const session = await account.createSession(userId, otp);
await fetch('/api/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({userId, otp}),
});
And I do this on the server side:
app/api/login/route.ts
export async function POST(request: NextRequest){
const { account } = await createAdminClient();
const { userId, otp } = await request.json();
const session = await account.createSession(userId, otp);
I always get the error: Invalid token passed in the request.
So now my question is: How can I share the session between client and server when using the OTP for auth? Thanks!
Recommended threads
- Cannot use custom SMTP for messaging (SM...
Hey there! I'm on Appwrite Self-hosted 1.9.0. I've never used the messaging feature before, always sent emails through functions or a custom backend, but I'v...
- 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...