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
@IamtheFuture Who would be accessing these API endpoints? Your users who already registerd with convex-auth?
yes, but they would be accessing from a mobile app
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
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
Auth in Functions | Convex Developer Hub
_If you're using Convex Auth, see the
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
Interface: UserIdentity | Convex Developer Hub
server.UserIdentity
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!
wow, great thanks so much, i will give this a try