Help with BETTER_AUTH_URL and Redirects for Server-Side Authentication in Figma Plugin
Hi everyone! I'm working on a Figma plugin and trying to handle authentication fully on the server-side using Better Auth. I've been running into some issues with the BETTER_AUTH_URL setting and the Google OAuth flow. Here's the situation:
But I'm struggling to set up the correct redirect and callback URLs. The user should interact with the server for all auth steps, and the client (Figma plugin) should just receive a response after authentication is complete.
- **Setting BETTER_AUTH_URL to the server URL (`http://localhost:5000`)**:
- Since I want all authentication logic on the server side, I set
BETTER_AUTH_URL=http://localhost:5000in my
..env - However, when I try to authenticate with Google, I get the following error:
- [Insert error message here if you have one]
- Since I want all authentication logic on the server side, I set
- **Changing BETTER_AUTH_URL to the client URL (`http://localhost:3000`)**:
- When I set
BETTER_AUTH_URL=http://localhost:3000(the client side), the OAuth flow works up to a point, and I get redirected back to: - But I want the callback to go to the server (
localhost:5000), so I manually change the callback URL tohttp://localhost:5000/api/auth/callback/google.
- When I set
- **Error after changing the callback URL**:
- When I manually change the callback URL to point to the server (
localhost:5000), I end up getting redirected tohttp://localhost:3000/?error=account_not_linked. This seems to break the authorization process, and it looks like the session isn't being linked properly.
- When I manually change the callback URL to point to the server (
But I'm struggling to set up the correct redirect and callback URLs. The user should interact with the server for all auth steps, and the client (Figma plugin) should just receive a response after authentication is complete.