IamtheFuture
IamtheFuture4mo ago

Nextjs Api auth header from external app

Hi everyone, I have a situation I want to call some nextjs api endpoint from my react navtive app, but I don’t want to make the nextjs api endpoint open, I want it authenticated(like passing auth headers to the api call from my mobile app), please how do I do this kind of authentication with convex-auth since convex-lucia-auth is no longer mentained anymore. Thanks
9 Replies
Omar
Omar4mo ago
@IamtheFuture Who would be accessing these API endpoints? Your users who already registerd with convex-auth?
IamtheFuture
IamtheFutureOP4mo ago
yes, but they would be accessing from a mobile app
Omar
Omar4mo ago
I don't think convex-auth will help you here directly, but given that your user would be logged into the app through convex-auth they can pass in their identification tokens (from convex-auth/oauth providers) into the auth headers of the API call to authenticate
IamtheFuture
IamtheFutureOP4mo ago
ok, great, then how do I check the token validity of the token on the api or middleware or is there a way I can just implement my own custom auth(password, oauth, magick-link, e.t.c) with convex. I know how to use lucia-auth well, maybe I can implement it with it
Omar
Omar4mo ago
so you need to setup the logic to authenticate the details the client passes to you against your auth tables https://docs.convex.dev/api/interfaces/server.UserIdentity
sshader
sshader4mo ago
If you do end up setting up Convex Auth, note that you could have a Convex HTTP Action (https://docs.convex.dev/functions/http-actions) instead of a NextJS API endpoint, which will more directly integrate with Convex Auth
HTTP Actions | Convex Developer Hub
HTTP actions allow you to build an HTTP API right in Convex!
IamtheFuture
IamtheFutureOP4mo ago
wow, great thanks so much, i will give this a try

Did you find this page helpful?