T
TanStack3mo ago
dependent-tan

oauth with atproto (Bluesky?)

Hi! First time trying tanstack-start. I am trying to implement the at-proto oauth flow with Better-Auth. However, getting into issues big time. First of all, i came across with this post: https://www.armannotes.com/posts/implementing-bluesky-oauth-authentication-in-nextjs-betterauth Its quite incomplete, and was written for NextJS, but still looked like a good starting point. I guess my main pain point is how to handle the BlueskyOAuthClient, on the server, and the cookies, but since I am not familiar with tanstack-start yet, I am probably doing multiple things wrong. Heres what I have so far: routes/api/bluesky.ts: https://gist.github.com/zilahir/6e2d310e18604db50b0dd551cd41aed7 i have also created the routes for the client-metadata.json and as well for the jwks.json. these are ok. So i think to point me to the right direction the main questions are: - where and how to initialise the NodeOAuthClient` - how to handle the cookies? but any other help is greatly appriciated!
1 Reply
like-gold
like-gold3mo ago
There should not be much differences between next and start
how to handle the cookies?
Tanstack start has getCookie, setCookie , and deleteCookie imported from @tanstack/react-start/server. So you can just replace any cookies().get, cookies().set, and cookies().delete with the one from start
import { getCookie, setCookie, deleteCookie } from '@tanstack/react-start/server'
import { getCookie, setCookie, deleteCookie } from '@tanstack/react-start/server'
where and how to initialise the NodeOAuthClient
From what I read, I think NodeOAuthClient should be server only, right? You can instantiate it anywhere you want though. To guarantee it not being accessed from the client-side, you can wrap it in serverOnly
import { serverOnly } from '@tanstack/react-start'

const BlueskyOAuthClient = serverOnly(() => new NodeOAuthClient({ /* the options here */ }))();
import { serverOnly } from '@tanstack/react-start'

const BlueskyOAuthClient = serverOnly(() => new NodeOAuthClient({ /* the options here */ }))();

Did you find this page helpful?