lock

Core

Authentication

Register and login against the Rust API, then reuse the access token for protected HTTP and WebSocket operations.

Register

Registration also adds the new Rust user to the selected group.

dart
final result = await sdk.auth.register(
  username: 'abed',
  email: 'abed@example.com',
  password: 'strong-password',
  groupId: 'RUST_GROUP_UUID',
  displayName: 'Abed',
  groupDescription: 'Registered from Flutter',
);

print(result.auth.user.id);
print(result.groupMember.id);

Login

dart
final auth = await sdk.auth.login(
  usernameOrEmail: 'abed',
  password: 'strong-password',
);

print(auth.user.username);
print(auth.token);

The SDK applies the returned token to subsequent requests automatically.

Current user

dart
final user = await sdk.auth.me();
print(user.id);
print(user.username);

Existing token

dart
sdk.setAccessToken(savedRustToken);

if (sdk.hasAccessToken) {
  final current = await sdk.auth.me();
}

Logout

dart
sdk.auth.logout();
// or
sdk.clearAccessToken();

Backward compatibility

dart
final auth = await sdk.users.loginUser(
  usernameOrEmail: 'abed',
  password: 'strong-password',
);
New integrations should use sdk.auth. The sdk.users

Token storage

The SDK keeps the token in memory. Persist it securely in your application if sessions must survive app restarts, then restore it with sdk.setAccessToken().