Skip to content

Commit ba5cb88

Browse files
committed
docs: update features and usage examples
- Updated features description - Added anonymous sign-in example - Added sign-out example - Clarified token management - Improved overall clarity
1 parent 4ab798e commit ba5cb88

File tree

1 file changed

+41
-21
lines changed

1 file changed

+41
-21
lines changed

README.md

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@ dependencies:
1818
## Features
1919
2020
- Abstracts authentication logic from the UI/business logic layers.
21-
- Provides methods mirroring `HtAuthClient`:
22-
- `authStateChanges`
23-
- `getCurrentUser`
24-
- `requestSignInCode`
25-
- `verifySignInCode`
26-
- `signInAnonymously`
27-
- `signOut`
28-
- `saveAuthToken(String token)`
29-
- `getAuthToken()`
30-
- `clearAuthToken()`
31-
- Propagates standardized `HtHttpException`s from the underlying client.
21+
- Provides methods for a complete authentication lifecycle:
22+
- `authStateChanges`: Stream of user authentication state.
23+
- `getCurrentUser`: Retrieves the current authenticated user.
24+
- `requestSignInCode`: Initiates email+code sign-in.
25+
- `verifySignInCode`: Verifies the code, saves the auth token, and returns the user.
26+
- `signInAnonymously`: Signs in anonymously, saves the auth token, and returns the user.
27+
- `signOut`: Signs out the user and clears the auth token.
28+
- Manages authentication token persistence internally using `HtKVStorageService`.
29+
- Exposes `saveAuthToken(String token)`, `getAuthToken()`, and `clearAuthToken()` for direct token manipulation if needed, but these are typically handled by the main auth flow methods.
30+
- Propagates standardized `HtHttpException`s from the underlying client and `StorageException`s from the storage service.
3231

3332
## Usage
3433

@@ -64,22 +63,43 @@ try {
6463
// Handle other errors
6564
}
6665
67-
// Example token handling:
68-
Future<void> handleSuccessfulLogin(String token) async {
69-
await authRepository.saveAuthToken(token);
70-
print('Auth token saved.');
66+
// Example usage:
67+
try {
68+
final user = await authRepository.verifySignInCode('[email protected]', '123456');
69+
// User is signed in, token is saved automatically.
70+
print('User signed in: ${user.id}');
71+
} on AuthenticationException catch (e) {
72+
// Handle invalid code
73+
} on StorageException catch (e) {
74+
// Handle failure to save token
75+
} catch (e) {
76+
// Handle other errors
77+
}
78+
79+
// Example of anonymous sign-in:
80+
try {
81+
final anonUser = await authRepository.signInAnonymously();
82+
// User is signed in anonymously, token is saved automatically.
83+
print('Anonymous user signed in: ${anonUser.id}');
84+
} catch (e) {
85+
// Handle errors
7186
}
7287
88+
// Example of sign-out:
89+
try {
90+
await authRepository.signOut();
91+
// User is signed out, token is cleared automatically.
92+
print('User signed out.');
93+
} catch (e) {
94+
// Handle errors
95+
}
96+
97+
// Direct token access (e.g., for HTTP client interceptors):
7398
Future<String?> getTokenForHttpClient() async {
7499
final token = await authRepository.getAuthToken();
75-
print('Retrieved token: $token');
100+
print('Retrieved token for HTTP client: $token');
76101
return token;
77102
}
78-
79-
Future<void> handleSignOut() async {
80-
await authRepository.clearAuthToken();
81-
print('Auth token cleared.');
82-
}
83103
```
84104

85105
## License

0 commit comments

Comments
 (0)