-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic auth plugin interface with support for anon logins
- Loading branch information
1 parent
0dea3e6
commit 3b17fbf
Showing
6 changed files
with
191 additions
and
63 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
packages/system/vyuh_core/lib/plugin/auth/anonymous_auth_plugin.dart
This file contains 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,83 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:vyuh_core/vyuh_core.dart'; | ||
|
||
final class AnonymousAuthPlugin extends AuthPlugin { | ||
AnonymousAuthPlugin() | ||
: super( | ||
title: 'Anonymous Auth Plugin', | ||
name: 'vyuh.plugin.auth.anonymous', | ||
); | ||
|
||
@override | ||
Future<void> deleteAccount() async { | ||
controller.add(User.anonymous); | ||
} | ||
|
||
@override | ||
Future<void> loginAnonymously() async { | ||
controller.add(User.anonymous); | ||
} | ||
|
||
@override | ||
Future<void> loginWithApple() async { | ||
controller.add(User.anonymous); | ||
} | ||
|
||
@override | ||
Future<void> loginWithEmailLink( | ||
{required String email, required String link}) async { | ||
controller.add(User.anonymous); | ||
} | ||
|
||
@override | ||
Future<void> loginWithEmailPassword( | ||
{required String username, required String password}) async { | ||
controller.add(User.anonymous); | ||
} | ||
|
||
@override | ||
Future<void> loginWithGithub() async { | ||
controller.add(User.anonymous); | ||
} | ||
|
||
@override | ||
Future<void> loginWithGoogle() async { | ||
controller.add(User.anonymous); | ||
} | ||
|
||
@override | ||
Future<void> loginWithLinkedin() async { | ||
controller.add(User.anonymous); | ||
} | ||
|
||
@override | ||
Future<void> loginWithMeta() async { | ||
controller.add(User.anonymous); | ||
} | ||
|
||
@override | ||
Future<void> loginWithMicrosoft() async { | ||
controller.add(User.anonymous); | ||
} | ||
|
||
@override | ||
Future<void> loginWithPhoneOtp( | ||
{required String phoneNumber, required String otp}) async { | ||
controller.add(User.anonymous); | ||
} | ||
|
||
@override | ||
Future<void> loginWithTwitter() async { | ||
controller.add(User.anonymous); | ||
} | ||
|
||
@override | ||
Future<void> logout() async { | ||
controller.add(User.anonymous); | ||
} | ||
|
||
@override | ||
Future<void> sendEmailLink( | ||
{required String email, required String clientId}) async {} | ||
} |
102 changes: 102 additions & 0 deletions
102
packages/system/vyuh_core/lib/plugin/auth/auth_plugin.dart
This file contains 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,102 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/cupertino.dart'; | ||
import 'package:vyuh_core/vyuh_core.dart'; | ||
|
||
abstract base class AuthPlugin extends Plugin { | ||
@protected | ||
var controller = StreamController<User>.broadcast(); | ||
|
||
@protected | ||
var _initialized = false; | ||
|
||
AuthPlugin({required super.name, required super.title}) | ||
: super(pluginType: PluginType.auth); | ||
|
||
Stream<User> get user { | ||
if (!_initialized) { | ||
throw StateError('Plugin not initialized'); | ||
} | ||
|
||
return controller.stream; | ||
} | ||
|
||
@override | ||
@mustCallSuper | ||
Future<void> dispose() async { | ||
_initialized = false; | ||
unawaited(controller.close()); | ||
} | ||
|
||
@override | ||
@mustCallSuper | ||
Future<void> init() async { | ||
if (_initialized) { | ||
return; | ||
} | ||
|
||
controller = StreamController<User>.broadcast(); | ||
|
||
_initialized = true; | ||
} | ||
|
||
Future<void> loginAnonymously(); | ||
|
||
Future<void> loginWithPhoneOtp( | ||
{required String phoneNumber, required String otp}); | ||
Future<void> loginWithEmailPassword( | ||
{required String username, required String password}); | ||
Future<void> sendEmailLink({required String email, required String clientId}); | ||
Future<void> loginWithEmailLink( | ||
{required String email, required String link}); | ||
|
||
Future<void> loginWithGoogle(); | ||
Future<void> loginWithMeta(); | ||
Future<void> loginWithApple(); | ||
Future<void> loginWithTwitter(); | ||
Future<void> loginWithGithub(); | ||
Future<void> loginWithLinkedin(); | ||
Future<void> loginWithMicrosoft(); | ||
|
||
Future<void> logout(); | ||
|
||
Future<void> deleteAccount(); | ||
} | ||
|
||
class User { | ||
final String id; | ||
final String? name; | ||
final String? email; | ||
final String? phoneNumber; | ||
final String? photoUrl; | ||
final LoginMethod loginMethod; | ||
|
||
const User({ | ||
required this.id, | ||
this.name, | ||
this.email, | ||
this.phoneNumber, | ||
this.photoUrl, | ||
this.loginMethod = LoginMethod.anonymous, | ||
}); | ||
|
||
bool get isAnonymous => this == anonymous; | ||
|
||
static const anonymous = User( | ||
id: 'anonymous', | ||
); | ||
} | ||
|
||
enum LoginMethod { | ||
anonymous, | ||
emailPassword, | ||
phoneOtp, | ||
emailLink, | ||
google, | ||
meta, | ||
apple, | ||
twitter, | ||
github, | ||
linkedin, | ||
microsoft, | ||
} |
This file contains 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 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 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