Authentication
Add sign-in to your Flutter app with type-safe APIs: email and social login across Google, Apple, GitHub, Facebook, and Microsoft, with managed sessions and scoped access, all in Dart.
Built-in authentication
Building authentication yourself means managing token storage, provider SDKs, session expiry, and secure password hashing, and a mistake in any of them is a security risk. Serverpod handles identity on the server: it stores users and sessions, integrates the providers, and exposes the result through the same generated, type-safe client as the rest of your API.
You protect an endpoint with a single override, read the signed-in user from the session, and gate access with scopes. The Flutter side gets drop-in sign-in and a session manager that keeps the user signed in across restarts and devices.
How it works
1Enable the providers you need
Register the identity providers your app needs when the server starts. Each provider is a single config object.
pod.initializeAuthServices(
tokenManagerBuilders: [serverSideSessionsConfig],
identityProviderBuilders: [
EmailIdpConfig(
secretHashPepper: pod.getPassword('emailSecretHashPepper')!,
),
googleIdpConfig,
appleIdpConfig,
],
);
2Require a signed-in user
Set requireLogin on an endpoint, and Serverpod rejects unauthenticated calls before your code runs.
class ProfileEndpoint extends Endpoint {
@override
bool get requireLogin => true;
Future<String> currentUserId(Session session) async {
return session.authenticated!.userIdentifier;
}
}
3Drop in the sign-in UI
The SignInWidget renders buttons for every provider you enabled, wired to your Serverpod client.
SignInWidget(
client: client,
onAuthenticated: _onSignedIn,
onError: _onError,
);
Social sign-in
Turn on the providers your app needs, including Google, Apple, GitHub, Facebook, Microsoft, and Firebase.
Email and password
Full email sign-up with verification, secure password hashing, and password reset flows, without writing a single line of authentication code yourself.
Managed sessions
Serverpod issues revocable auth keys and keeps users signed in across app restarts through the client session manager. Set it up once when you create your client, and revoke a device or all sessions at any time.
final client = Client(serverUrl)
..connectivityMonitor = FlutterConnectivityMonitor()
..authSessionManager = FlutterAuthSessionManager();
await client.auth.initialize();
Scoped access
Use scopes to restrict access to a specific set of users with requireLogin and requiredScopes. Authorization lives next to the code it protects.
Everything included
Why Serverpod
Works with
Google Apple GitHub Facebook Microsoft Firebase
Frequently asked questions
Does Serverpod support social login?
Yes. You can enable Google, Apple, GitHub, Facebook, and Microsoft sign-in and expose them through the generated client.
Does it support Sign in with Apple and Google?
Yes. Both are first-class providers with drop-in Flutter buttons and server-side verification.
Can I use email and password authentication?
Yes. Serverpod handles sign-up, email verification, secure password hashing, and password reset.
Does it work with Firebase Authentication?
Yes. Firebase is a first-class identity provider. The server verifies Firebase ID tokens and issues Serverpod sessions.
Can I add custom roles and permissions?
Yes. Use scopes to restrict access to an endpoint to a specific set of users.
When should I not use this?
Serverpod auth is for apps where Serverpod is your backend. If your Flutter app talks to an existing backend, authenticate there instead.