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:

  1. **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:5000 in my
      .env
      .
    • However, when I try to authenticate with Google, I get the following error:
      • [Insert error message here if you have one]
    How do I properly configure Better Auth so that the server handles the OAuth flow?
  2. **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:
      http://localhost:3000/api/auth/callback/google?state={"code":"xxxxx","callbackURL":"http://localhost:3000/"}&code=4/xxxx-xxxx-xxxx&scope=email+profile+openid...
    • But I want the callback to go to the server (localhost:5000), so I manually change the callback URL to http://localhost:5000/api/auth/callback/google.
  3. **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 to http://localhost:3000/?error=account_not_linked. This seems to break the authorization process, and it looks like the session isn't being linked properly.
My goal is to handle authentication entirely on the server side for my Figma plugin, that's why for understanding better auth i am trying this poc with react(next js).

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.
Was this page helpful?