Help in Implementing OAuth Authentication with Appwrite in Next.js 15 + Types with SSR and Cookies
- 1
- Web

I'm working on implementing OAuth authentication in my Next.js application using Appwrite as the backend
Technical Environment: Next.js (lastest) Appwrite (lastest) Authentication Type: OAuth (provider: Google/GitHub/etc.) Node-appwrite/appwrite The problem is that node-appwrite doest have oauth logun and I want to store the cookies as well I want to use react-query to store user data

node-appwrite does allow for oauth login.
https://appwrite.io/docs/references/cloud/server-nodejs/account#createOAuth2Token

You can check out this tutorial for oauth in nextjs ssr

Thanks!!

but How to sotre the cookies of the OAuth?

TYhis its a reference ``` app.get('/oauth/success', async (req, res) => { const account = new Account(adminClient);
// Get the userId and secret from the URL parameters
const { userId, secret } = req.query;
try {
// Create the session using the Appwrite client
const session = await account.createSession(userId, secret);
// Set the session cookie
res.cookie('session', session.secret, { // Use the session secret as the cookie value
httpOnly: true,
secure: true,
sameSite: 'strict',
maxAge: sesion.expire
path: '/',
});
res.status(200).json({ success: true });
} catch (e) {
res.status(400).json({ success: false, error: e.message });
}
});``` but the main problem its how to get the Token if Im using Appwrite Cloud and Im a Pro user

Go ahead and checkout the tutorial I linked you.
You'll need to setup a callback for the oauth redirect to get the session and store it in the cookie.
https://appwrite.io/docs/tutorials/nextjs-ssr-auth/step-7#oauth-callback

Cool, Thanks

Hmm, This its unexpected Error fetching user: AppwriteException: app.6723dcc0001423226a2f@service.cloud.appwrite.io (role: applications) missing scope (account)
at _Client.call (turbopack://[project]/node_modules/node-appwrite/src/client.ts:347:8)

to use account.get you need to create a new client that sets the users session on the client

try {
const { account } = await createAdminClient();
// @ts-expect-error - Next.js 15 types issue
const sessionId = await cookies().get("auth_session")?.value;
if (!sessionId) {
return null;
}
const user = await account.get();
return user;
} catch (error) {
console.error('Error fetching user:', error);
return null;
}
} ``` This its my code its good?

I need to create a new client

?

Yes, you'll need an admin client and a session client.

The session client acts on behalf of a user.

I highly recommend looking at this tutorial Guille and I have provided.

Thanks so much!!, Im still new in appwrite
Recommended threads
- Subdomain failed verification
So I wanted to do a custom subdomain, because local storage doesn't work for me, but I've tried it a long time ago, it didn't work for me, and now I'm trying ag...
- [Node.js SDK] Bypass 2GB file limit?
Hello. Using either InputFile.fromPath or InputFile.fromBuffer throws this error: File size (2295467305) is greater than 2 GiB Bucket limit etc. is setup corre...
- Relationship null, even when relationshi...
Hi Everyone, im experiencing issues with set relation data. When im setting the document id from the related database most of them seem fine, except one table. ...
