-
Notifications
You must be signed in to change notification settings - Fork 1
feat(llc): implement real guest token flow via createGuest #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
renefloor
wants to merge
6
commits into
main
Choose a base branch
from
renefloor/flu-373-guest-and-anonymous-login
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d7de531
feat(llc): implement real guest token flow via createGuest
renefloor d5df62f
chore: trigger CI re-run
renefloor d3e686a
test(llc): add coverage for guest user token flow
renefloor 477415c
test(llc): fix lint warnings in guest user test
renefloor c199264
Fix guest token userId
renefloor a84144d
Make tokenManager mutable
renefloor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import 'package:stream_feeds/stream_feeds.dart'; | ||
|
|
||
| Future<void> regularUserLogin() async { | ||
| // Regular user: provide a JWT token (from your server). | ||
| final client = StreamFeedsClient( | ||
| apiKey: '<your_api_key>', | ||
| user: const User(id: 'alice'), | ||
| tokenProvider: TokenProvider.static(UserToken('<your_jwt_token>')), | ||
| ); | ||
| await client.connect(); | ||
| } | ||
|
|
||
| Future<void> dynamicTokenProvider() async { | ||
| // Dynamic token provider: fetches a new token from your server | ||
| // when the current one expires. | ||
| final client = StreamFeedsClient( | ||
| apiKey: '<your_api_key>', | ||
| user: const User(id: 'alice'), | ||
| tokenProvider: TokenProvider.dynamic((userId) async { | ||
| // Fetch a fresh JWT for `userId` from your backend. | ||
| final token = await fetchTokenFromYourServer(userId); | ||
| return UserToken(token); | ||
| }), | ||
| ); | ||
| await client.connect(); | ||
| } | ||
|
|
||
| // Placeholder for your server token fetch | ||
| Future<String> fetchTokenFromYourServer(String userId) async => '<jwt>'; | ||
|
|
||
| Future<void> guestUserLogin() async { | ||
| // Guest user: the SDK automatically calls POST /api/v2/guest to obtain | ||
| // a temporary JWT — no tokenProvider is needed. | ||
| // Guest users have full read/write access and a real WebSocket connection, | ||
| // but their session is temporary and not tied to a persistent account. | ||
| final client = StreamFeedsClient( | ||
| apiKey: '<your_api_key>', | ||
| user: User.guest('guest-${DateTime.now().millisecondsSinceEpoch}'), | ||
| ); | ||
| await client.connect(); // Guest JWT is fetched automatically on connect. | ||
|
|
||
| final feed = client.feed(group: 'user', id: client.user.id); | ||
| await feed.getOrCreate(); | ||
| } | ||
|
|
||
| Future<void> anonymousUserLogin() async { | ||
| // Anonymous user: read-only access with no JWT or WebSocket connection. | ||
| // Use this for public feeds that don't require authentication. | ||
| // Note: calling connect() throws for anonymous users. | ||
| final client = StreamFeedsClient( | ||
| apiKey: '<your_api_key>', | ||
| user: const User.anonymous(), | ||
| ); | ||
|
|
||
| // Read public feed data without connecting. | ||
| final feed = client.feed(group: 'user', id: 'alice'); | ||
| await feed.getOrCreate(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should put this in the UserRepository from https://github.com/GetStream/stream-feeds-flutter/pull/111/changes#diff-650fcf6bedea499ffcb82f20d5cda7f3a5c6fcb02a19c1bb398a4347c61cc5eb