AuthRepository class

Manages user authentication and profile data.

final auth = ref.watch(authRepositoryProvider);

// Login
final user = await auth.login('111360109', 'password');

// Observe user profile (auto-refreshes when stale)
final stream = auth.watchUser();

// Force refresh (for pull-to-refresh)
await auth.refreshUser();

Constructors

AuthRepository({required PortalService portalService, required StudentQueryService studentQueryService, required AppDatabase database, required FlutterSecureStorage secureStorage, required void onSessionCreated(), required void onSessionDestroyed([LoginException?])})

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

changePassword(String currentPassword, String newPassword) Future<void>
Changes the user's NTUT Portal password.
getAvatar() Future<File?>
Gets the current user's avatar image, with local caching.
getSsoUrl(String serviceCode) Future<Uri>
Gets a browser-openable SSO URL for serviceCode.
login(String username, String password) Future<User>
Authenticates with NTUT Portal and saves the user profile.
logout() Future<void>
Logs out and clears all local user data and stored credentials.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
refreshUser() Future<void>
Refreshes login-level fields (avatar, name, email) via Portal login, and academic data (profile, registrations) via the student query service. The login call also establishes a fresh session for the subsequent SSO calls.
toString() String
A string representation of this object.
inherited
uploadAvatar(Uint8List imageBytes) Future<void>
Uploads a new avatar image, replacing the current one.
watchActiveRegistration() Stream<UserRegistration?>
Watches the user's active registration (where enrollment status is "在學").
watchUser() Stream<User?>
Gets the current user with automatic cache refresh. Watches the current user with automatic background refresh.
withAuth<T>(Future<T> call(), {List<PortalServiceCode> sso = const []}) Future<T>
Executes call with automatic re-authentication on session expiry.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

maxAvatarSize → const int
Maximum avatar file size (20 MB), matching NTUT's client-defined limit.