Skip to content

FluxbaseAuth

//fluxbase-kotlin/io.github.nimbleflux.fluxbase.auth/FluxbaseAuth

class FluxbaseAuth(http: FluxbaseHttpClient, autoRefresh: Boolean = true, storage: StorageAdapter = MemoryStorage())

Authentication module — port of FluxbaseAuth from sdk/src/auth.ts.

Manages the user session: sign in/up/out, session persistence, and auth state change events. The session is stored via a StorageAdapter (default: MemoryStorage for JVM; Android injects an EncryptedSharedPreferences-backed implementation).

jvm

http the shared FluxbaseHttpClient for making API calls.
autoRefresh whether to automatically refresh the token before expiry (default true; disabled in tests). TS default is true (auth.ts:55).
storage the StorageAdapter for session persistence.
FluxbaseAuth [jvm]
constructor(http: FluxbaseHttpClient, autoRefresh: Boolean = true, storage: StorageAdapter = MemoryStorage())
Name Summary
Companion [jvm]
object Companion
Name Summary
currentSession [jvm]
var currentSession: AuthSession?
The current session, or null if not authenticated.
currentUser [jvm]
val currentUser: User?
The current user, or null if not authenticated.
Name Summary
deleteAccount [jvm]
suspend fun deleteAccount(password: String? = null)
Delete the current user’s account (self-service account deletion). DELETEs to /api/v1/auth/account with an optional {password} body — required when the account has a password credential; OAuth-only accounts pass null. On success the local session is cleared so the SDK stops sending the revoked access token. Failures (403 wrong password, 429 rate limit) throw and leave the session untouched.
disable2FA [jvm]
suspend fun disable2FA(password: String): FluxbaseResponse<TwoFactorDisableResponse>
POST /api/v1/auth/2fa/disable with {password} → disables 2FA.
enable2FA [jvm]
suspend fun enable2FA(code: String): FluxbaseResponse<TwoFactorEnableResponse>
POST /api/v1/auth/2fa/enable with {code} → enables 2FA, returns backup codes.
exchangeCodeForSession [jvm]
suspend fun exchangeCodeForSession(code: String, state: String? = null): FluxbaseResponse<AuthResult>
Exchange the OAuth authorization code (from the deep-link/callback) for a session and establish it. GETs /api/v1/auth/oauth/{provider}/callback?code&state&redirect_uri. Port of exchangeCodeForSession() (auth.ts:955).
get2FAStatus [jvm]
suspend fun get2FAStatus(): FluxbaseResponse<TwoFactorStatusResponse>
GET /api/v1/auth/2fa/status → returns enrolled factors.
getAuthConfig [jvm]
suspend fun getAuthConfig(): FluxbaseResponse<AuthConfig>
Get the server’s auth configuration (signup enabled, OAuth providers, password rules). GETs /api/v1/auth/config. Port of getAuthConfig() in auth.ts.
getCurrentUser [jvm]
suspend fun getCurrentUser(): FluxbaseResponse<User>
Get the current user from the server. GETs /api/v1/auth/user. Port of getCurrentUser() in auth.ts.
getOAuthProviders [jvm]
suspend fun getOAuthProviders(): FluxbaseResponse<List<OAuthProviderInfo>>
List the app-login-enabled OAuth providers. GETs /api/v1/auth/oauth/providers. Port of getOAuthProviders() (auth.ts:913).
getOAuthUrl [jvm]
suspend fun getOAuthUrl(provider: String, options: OAuthOptions = OAuthOptions()): FluxbaseResponse<OAuthUrlResponse>
Get the authorization URL for provider to open in a system browser. GETs /api/v1/auth/oauth/{provider}/authorize. Port of getOAuthUrl() (auth.ts:923).
onAuthStateChange [jvm]
fun onAuthStateChange(callback: (AuthState) -> Unit): () -> Unit
Register a callback for auth state changes. Returns a function to unsubscribe.
refreshSession [jvm]
suspend fun refreshSession(): FluxbaseResponse<AuthSession>
Refresh the current session using the stored refresh token. POSTs to /api/v1/auth/refresh with {refresh_token}. On success, updates the session and emits TOKEN_REFRESHED.
sendPasswordReset [jvm]
suspend fun sendPasswordReset(email: String): FluxbaseResponse<Unit>
Send a password reset email. POSTs /api/v1/auth/password/reset. Port of sendPasswordReset() in auth.ts.
setup2FA [jvm]
suspend fun setup2FA(): FluxbaseResponse<TwoFactorSetupResponse>
POST /api/v1/auth/2fa/setup → returns TOTP secret + QR code.
signIn [jvm]
suspend fun signIn(email: String, password: String): FluxbaseResponse<AuthResult>
Sign in with email and password.
signInWithPassword [jvm]
suspend fun signInWithPassword(email: String, password: String): FluxbaseResponse<AuthResult>
Alias for signIn — Supabase-compatible method name.
signOut [jvm]
suspend fun signOut()
Sign out. POSTs to /api/v1/auth/signout, clears the session, and restores the anon key on the HTTP client.
signUp [jvm]
suspend fun signUp(email: String, password: String): FluxbaseResponse<AuthResult>
Sign up with email and password.
updateUser [jvm]
suspend fun updateUser(attributes: Map<String, Any>): FluxbaseResponse<User>
Update the user’s attributes. PATCHes /api/v1/auth/user. Port of updateUser() in auth.ts.
verify2FA [jvm]
suspend fun verify2FA(userId: String, code: String): FluxbaseResponse<AuthResult>
POST /api/v1/auth/2fa/verify with {user_id, code} — completes a 2FA login challenge. On success, establishes a session from the returned tokens.