Skip to content

Commit 7f1a582

Browse files
authored
Merge pull request #3 from flutter-news-app-full-source-code/build/update-deps
Build/update deps
2 parents 3782e6f + 8ff4f74 commit 7f1a582

File tree

6 files changed

+494
-178
lines changed

6 files changed

+494
-178
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# See https://www.dartlang.org/guides/libraries/private-files
2-
3-
# Files and directories created by pub
41
.dart_tool/
52
.packages
63
build/
7-
pubspec.lock
4+
coverage/

README.md

Lines changed: 27 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,40 @@
1-
# auth_inmemory
1+
<div align="center">
2+
<img src="https://avatars.githubusercontent.com/u/202675624?s=400&u=dc72a2b53e8158956a3b672f8e52e39394b6b610&v=4" alt="Flutter News App Toolkit Logo" width="220">
3+
<h1>Auth In-Memory</h1>
4+
<p><strong>An in-memory implementation of the `AuthClient` interface for the Flutter News App Toolkit.</strong></p>
5+
</div>
26

3-
![coverage: percentage](https://img.shields.io/badge/coverage-XX-green)
4-
[![style: very good analysis](https://img.shields.io/badge/style-very_good_analysis-B22C89.svg)](https://pub.dev/packages/very_good_analysis)
5-
[![License: PolyForm Free Trial](https://img.shields.io/badge/License-PolyForm%20Free%20Trial-blue)](https://polyformproject.org/licenses/free-trial/1.0.0)
7+
<p align="center">
8+
<img src="https://img.shields.io/badge/coverage-13%25-red?style=for-the-badge" alt="coverage">
9+
<a href="https://flutter-news-app-full-source-code.github.io/docs/"><img src="https://img.shields.io/badge/LIVE_DOCS-VIEW-slategray?style=for-the-badge" alt="Live Docs: View"></a>
10+
<a href="https://github.com/flutter-news-app-full-source-code"><img src="https://img.shields.io/badge/MAIN_PROJECT-BROWSE-purple?style=for-the-badge" alt="Main Project: Browse"></a>
11+
</p>
612

7-
An in-memory implementation of the `AuthClient` interface. This package provides a mock authentication client that operates entirely on in-memory data, making it suitable for demonstration purposes, local development, and testing without requiring a live backend.
13+
This `auth_inmemory` package provides an in-memory implementation of the `AuthClient` interface within the [**Flutter News App Full Source Code Toolkit**](https://github.com/flutter-news-app-full-source-code). It offers a mock authentication client that operates entirely on in-memory data, making it suitable for demonstration purposes, local development, and testing without requiring a live backend. This package simulates various authentication flows, ensuring consistent behavior and robust error handling based on the `auth_client` contract.
814

9-
### Getting Started
15+
## ⭐ Feature Showcase: Simplified Authentication Testing & Development
1016

11-
Add the following to your `pubspec.yaml` dependencies:
17+
This package offers a comprehensive set of features for managing authentication operations in a simulated environment.
1218

13-
```yaml
14-
dependencies:
15-
auth_inmemory:
16-
git:
17-
url: https://github.com/flutter-news-app-full-source-code/auth-inmemory
18-
```
19+
<details>
20+
<summary><strong>🧱 Core Functionality</strong></summary>
1921

20-
### Features
22+
### 🚀 `AuthClient` Implementation
23+
- **`AuthInmemory` Class:** A concrete in-memory implementation of the `AuthClient` interface, providing a standardized way to simulate authentication.
24+
- **Simulated Authentication Flows:** Implements `requestSignInCode`, `verifySignInCode`, `signInAnonymously`, and `signOut` to simulate various authentication processes.
25+
- **Reactive State Changes:** Provides `authStateChanges` (a stream that emits the current authenticated `User` or `null` on state changes) and `getCurrentUser` to retrieve the current user.
2126

22-
This package implements the `AuthClient` interface, providing the following in-memory simulated authentication methods:
27+
### 🌐 Debugging & Validation
28+
- **Privileged Flow Simulation:** Supports an `isDashboardLogin` flag in `requestSignInCode` and `verifySignInCode` to simulate privileged flows, allowing testing of admin-specific authentication logic (e.g., only `[email protected]` is allowed).
29+
- **Token Retrieval:** Includes a `currentToken` getter to retrieve the simulated authentication token for inspection during development.
2330

24-
* `authStateChanges`: A stream that emits the current authenticated `User` or `null` on state changes.
25-
* `getCurrentUser`: Retrieves the currently authenticated `User`.
26-
* `requestSignInCode`: Simulates sending a sign-in code to an email. This method supports an optional `isDashboardLogin` flag. When `true`, it simulates a privileged flow where only `[email protected]` is allowed to request a code; otherwise, it throws an `UnauthorizedException`.
27-
* `verifySignInCode`: Simulates verifying a sign-in code and authenticating a user. This method also supports an optional `isDashboardLogin` flag. When `true`, it simulates a privileged flow where only `[email protected]` can successfully verify a code (throwing a `NotFoundException` for other emails) and the authenticated user is assigned the `UserRoles.admin` role.
28-
* `signInAnonymously`: Simulates signing in a user anonymously.
29-
* `signOut`: Simulates signing out the current user.
30-
* `currentToken`: A custom getter to retrieve the simulated authentication token.
31-
32-
### Usage
33-
34-
Here's how you can use `AuthInmemory` in your application for demo or testing environments:
35-
36-
```dart
37-
import 'package:auth_inmemory/auth_inmemory.dart';
38-
import 'package:core/core.dart'; // For User and AuthSuccessResponse
39-
40-
void main() async {
41-
final authClient = AuthInmemory();
42-
43-
// Listen to authentication state changes
44-
authClient.authStateChanges.listen((user) {
45-
if (user != null) {
46-
print('User authenticated: ${user.email ?? 'Anonymous'}');
47-
} else {
48-
print('User signed out.');
49-
}
50-
});
51-
52-
// Simulate anonymous sign-in
53-
try {
54-
final anonymousAuthResponse = await authClient.signInAnonymously();
55-
print('Signed in anonymously. User ID: ${anonymousAuthResponse.user.id}');
56-
print('Current Token: ${authClient.currentToken}');
57-
} catch (e) {
58-
print('Anonymous sign-in failed: $e');
59-
}
60-
61-
// Simulate email sign-in flow
62-
const testEmail = '[email protected]';
63-
try {
64-
await authClient.requestSignInCode(testEmail);
65-
print('Sign-in code requested for $testEmail');
66-
67-
// In a real app, the user would input the code received via email
68-
const code = '123456'; // Hardcoded code for in-memory demo
69-
70-
final verifiedAuthResponse =
71-
await authClient.verifySignInCode(testEmail, code);
72-
print('Verified sign-in for ${verifiedAuthResponse.user.email}');
73-
print('Current Token: ${authClient.currentToken}');
74-
} on InvalidInputException catch (e) {
75-
print('Invalid input: ${e.message}');
76-
} on AuthenticationException catch (e) {
77-
print('Authentication failed: ${e.message}');
78-
} catch (e) {
79-
print('Sign-in failed: $e');
80-
}
81-
82-
// Get current user
83-
final currentUser = await authClient.getCurrentUser();
84-
print('Current user (after operations): ${currentUser?.email}');
85-
86-
// Simulate sign-out
87-
try {
88-
await authClient.signOut();
89-
print('User signed out successfully.');
90-
} catch (e) {
91-
print('Sign-out failed: $e');
92-
}
93-
}
94-
```
31+
### 🛡️ Standardized Error Handling
32+
- **`HttpException` Propagation:** Throws standard `HttpException` subtypes (e.g., `UnauthorizedException`, `NotFoundException`, `AuthenticationException`, `InvalidInputException`) from `core` on simulated failures, ensuring consistent error handling in a testing context.
9533

34+
> **💡 Your Advantage:** This package provides a reliable, in-memory authentication client that simplifies testing and development of authentication-related features. It eliminates the need for external backend dependencies during development, offering immediate feedback and consistent behavior for your authentication logic, especially for complex scenarios like privileged logins.
9635
36+
</details>
9737

9838
## 🔑 Licensing
9939

100-
This package is source-available and licensed under the [PolyForm Free Trial 1.0.0](LICENSE). Please review the terms before use.
101-
102-
For commercial licensing options that grant the right to build and distribute unlimited applications, please visit the main [**Flutter News App - Full Source Code Toolkit**](https://github.com/flutter-news-app-full-source-code) organization.
40+
This `auth_inmemory` package is an integral part of the [**Flutter News App Full Source Code Toolkit**](https://github.com/flutter-news-app-full-source-code). For comprehensive details regarding licensing, including trial and commercial options for the entire toolkit, please refer to the main toolkit organization page.

analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include: package:very_good_analysis/analysis_options.8.0.0.yaml
1+
include: package:very_good_analysis/analysis_options.9.0.0.yaml
22
analyzer:
33
errors:
44
document_ignores: ignore

coverage/lcov.info

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)