How should the Flutter client make the correct request? #754

Closed
opened 2026-03-13 08:02:58 -05:00 by GiteaMirror · 8 comments
Owner

Originally created by @quentin996007 on GitHub (Feb 28, 2025).

Is this suited for github?

The overall feeling is good, but I have a question. When my client is Flutter and the server is Elysia.js, how can I let Flutter access the auth service?

Describe the solution you'd like

I hope that this auth service can be used not only in Web front-end applications, but also in Flutter or native apps.

Describe alternatives you've considered

Initiate HTTP request directly?

Additional context

No response

Originally created by @quentin996007 on GitHub (Feb 28, 2025). ### Is this suited for github? - [x] #1607 ### Is your feature request related to a problem? Please describe. The overall feeling is good, but I have a question. When my client is Flutter and the server is Elysia.js, how can I let Flutter access the auth service? ### Describe the solution you'd like I hope that this auth service can be used not only in Web front-end applications, but also in Flutter or native apps. ### Describe alternatives you've considered Initiate HTTP request directly? ### Additional context _No response_
GiteaMirror added the integration label 2026-03-13 08:02:58 -05:00
Author
Owner

@abellaismail7 commented on GitHub (Mar 14, 2025):

You can install the openapi plugin and explore the sign-in endpoints
For social auth I recommend using ID token extracted from auth library of the service you are using. (and send it to signin/social endpoint in better-auth)

@abellaismail7 commented on GitHub (Mar 14, 2025): You can install the openapi plugin and explore the sign-in endpoints For social auth I recommend using ID token extracted from auth library of the service you are using. (and send it to signin/social endpoint in better-auth)
Author
Owner

@jordanliu commented on GitHub (Apr 16, 2025):

@quentin996007 did you ever implement this e2e?

@jordanliu commented on GitHub (Apr 16, 2025): @quentin996007 did you ever implement this e2e?
Author
Owner

@quentin996007 commented on GitHub (Apr 19, 2025):

@quentin996007 did you ever implement this e2e?

No, I just started learning this auth plugin. I used to implement my own auth system.

@quentin996007 commented on GitHub (Apr 19, 2025): > [@quentin996007](https://github.com/quentin996007) did you ever implement this e2e? No, I just started learning this auth plugin. I used to implement my own auth system.
Author
Owner

@ekakshjanweja commented on GitHub (Apr 22, 2025):

Hey I have been working on a client side sdk for flutter

maybe you could check it out https://github.com/ekakshjanweja/better_auth_flutter

@ekakshjanweja commented on GitHub (Apr 22, 2025): Hey I have been working on a client side sdk for flutter maybe you could check it out https://github.com/ekakshjanweja/better_auth_flutter
Author
Owner

@jordanliu commented on GitHub (Jun 3, 2025):

@Kinfe123 I wouldn't mind working on an official flutter sdk, is this something on the roadmap? If so, I can submit a proposal and start working on it.

@jordanliu commented on GitHub (Jun 3, 2025): @Kinfe123 I wouldn't mind working on an official flutter sdk, is this something on the roadmap? If so, I can submit a proposal and start working on it.
Author
Owner

@ekakshjanweja commented on GitHub (Jun 4, 2025):

@Kinfe123 I wouldn't mind working on an official flutter sdk, is this something on the roadmap? If so, I can submit a proposal and start working on it.

I have been working on an unofficial SDK, would love to contribute if there's an official one.

Check it out
https://pub.dev/packages/better_auth_flutter

@ekakshjanweja commented on GitHub (Jun 4, 2025): > @Kinfe123 I wouldn't mind working on an official flutter sdk, is this something on the roadmap? If so, I can submit a proposal and start working on it. I have been working on an unofficial SDK, would love to contribute if there's an official one. Check it out https://pub.dev/packages/better_auth_flutter
Author
Owner

@erickweil commented on GitHub (Jul 15, 2025):

While a integration isn't ready is perfectly fine to use the OpenAPI plugin docs to see how routes work and fetch them the same way as any REST API (even plugins will have their routes documented!), but I had problems with the social login, so i'm letting my solution here hoping to help other people with the same problem.

For login with google on Flutter I ended up doing the following:

  1. On the backend I added the expo plugin and added myapp:// to trustedOrigins
export const auth = betterAuth({
  /** ... other configs ... */
  plugins: [
    openAPI(),
    expo() as unknown as BetterAuthPlugin
  ],
  trustedOrigins: [...process.env.CORS_ORIGINS.split(","), "myapp://"],
});
  1. On flutter side I call the social sign in endpoint with custom callbackUrl:
final resp = await DioClient.instance.post(
  '/api/auth/sign-in/social',
  data: {
    'provider': 'google',
    'callbackURL': 'myapp://',
  },
);

// Present the dialog to the user
final result = await FlutterWebAuth2.authenticate(
  url: resp.data['url'] as String,
  callbackUrlScheme: "myapp",
  options: const FlutterWebAuth2Options(useWebview: false),
);

This way the cookie will be in the result as a query parameter (server sided expo plugin does this) and you call either store it as a cookie or extract the session_token and pass the Authorization header (in conjunction with bearer plugin on backend).

One could use the idToken flow instead, calling google oauth via native integration, but for some providers the external browser is the only option (e.g Facebook).

@erickweil commented on GitHub (Jul 15, 2025): While a integration isn't ready is perfectly fine to use the OpenAPI plugin docs to see how routes work and fetch them the same way as any REST API (even plugins will have their routes documented!), but I had problems with the social login, so i'm letting my solution here hoping to help other people with the same problem. For login with google on Flutter I ended up doing the following: 1. On the backend I added the expo plugin and added `myapp://` to trustedOrigins ``` export const auth = betterAuth({ /** ... other configs ... */ plugins: [ openAPI(), expo() as unknown as BetterAuthPlugin ], trustedOrigins: [...process.env.CORS_ORIGINS.split(","), "myapp://"], }); ``` 2. On flutter side I call the social sign in endpoint with custom callbackUrl: ``` final resp = await DioClient.instance.post( '/api/auth/sign-in/social', data: { 'provider': 'google', 'callbackURL': 'myapp://', }, ); // Present the dialog to the user final result = await FlutterWebAuth2.authenticate( url: resp.data['url'] as String, callbackUrlScheme: "myapp", options: const FlutterWebAuth2Options(useWebview: false), ); ``` This way the cookie will be in the result as a query parameter (server sided expo plugin does this) and you call either store it as a cookie or extract the session_token and pass the Authorization header (in conjunction with bearer plugin on backend). > One could use the idToken flow instead, calling google oauth via native integration, but for some providers the external browser is the only option (e.g Facebook).
Author
Owner

@ping-maxwell commented on GitHub (Sep 30, 2025):

For now lets leave this issue to solving the OPs question directly:

Initiate HTTP request directly?

Yeah - normal HTTP requests will work. Some plugins however do require front-end JS code to be ran (such as passkey plugin if I remember correctly). So those cases won't work out unless you can manually implement it.

@ping-maxwell commented on GitHub (Sep 30, 2025): For now lets leave this issue to solving the OPs question directly: > Initiate HTTP request directly? Yeah - normal HTTP requests will work. Some plugins however do require front-end JS code to be ran (such as passkey plugin if I remember correctly). So those cases won't work out unless you can manually implement it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#754