Using Custom API with Better Auth While Leveraging Session Management
Hi Better Auth community! I need help with a specific integration scenario.
My Goal:
I want to use my custom API endpoints for authentication (login/registration) but still leverage Better Auth's session management and other features. Essentially, I want Better Auth to be the frontend interface while my custom API handles the actual authentication in the background.
Current Setup:
I've created a custom auth provider and tried to integrate it with Better Auth, but I'm struggling with how to properly hook into Better Auth's authentication flow while using my own API endpoints.
Specific Questions:
Any guidance would be greatly appreciated! Or if anyone can help me to provide specific repository which can solve my problem
My Goal:
I want to use my custom API endpoints for authentication (login/registration) but still leverage Better Auth's session management and other features. Essentially, I want Better Auth to be the frontend interface while my custom API handles the actual authentication in the background.
Current Setup:
- Next.js application with Better Auth
- Custom API endpoints:
https://domain/v1/sign-in(uses "identifier" instead of "email")https://domain/v1/sign-up(uses "identifier" instead of "email")
- When a user logs in through Better Auth's interface, I want to intercept that request
- Route the authentication to my custom API
- Return the response to Better Auth
- Have Better Auth create and manage the session based on my API's response
I've created a custom auth provider and tried to integrate it with Better Auth, but I'm struggling with how to properly hook into Better Auth's authentication flow while using my own API endpoints.
Specific Questions:
- How can I properly configure Better Auth to use my custom API while still managing sessions?
- Is there a recommended approach for intercepting Better Auth's authentication flow?
- What's the best way to map my API's response format to what Better Auth expects?
Any guidance would be greatly appreciated! Or if anyone can help me to provide specific repository which can solve my problem