Skip to content

Commit

Permalink
Add back Auth provider types
Browse files Browse the repository at this point in the history
  • Loading branch information
dnys1 committed Mar 8, 2024
1 parent dc8d2de commit 8c5a43b
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 11 deletions.
8 changes: 8 additions & 0 deletions packages/celest/lib/celest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ library celest;

export 'package:celest_core/celest_core.dart';

/// Auth
export 'src/auth/auth.dart';
export 'src/auth/auth_provider.dart';

/// Config
export 'src/config/env.dart';

/// Core
export 'src/core/cloud_widget.dart';
export 'src/core/context.dart';
export 'src/core/project.dart';

/// Functions
export 'src/functions/cloud_api.dart';
export 'src/functions/cloud_function.dart';

/// Grants
export 'src/grants/grants.dart';
10 changes: 5 additions & 5 deletions packages/celest/lib/src/auth/auth_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
/// An authentication provider which can be used to sign in to Celest.
///
/// Currently, Celest supports the following authentication methods:
/// - [AuthProvider.google] Sign in with Google
/// - [AuthProvider.email] Email sign-in with OTP codes.
/// {@endtemplate}
sealed class AuthProvider {
const AuthProvider();

/// A provider which enables Sign in with Google.
const factory AuthProvider.google() = _GoogleAuthProvider;
/// A provider which enables email sign-in with OTP codes.
const factory AuthProvider.email() = _EmailAuthProvider;
}

final class _GoogleAuthProvider extends AuthProvider {
const _GoogleAuthProvider();
final class _EmailAuthProvider extends AuthProvider {
const _EmailAuthProvider();
}
30 changes: 30 additions & 0 deletions packages/celest/lib/src/core/context.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:celest/celest.dart';

/// The context of a [CloudFunction] invocation.
abstract final class Context {
const Context._();

/// A context reference to the [User] invoking a [CloudFunction].
///
/// ## Example
///
/// To inject a user into an `@authenticated` function:
///
/// ```dart
/// @authenticated
/// Future<void> sayHello({
/// @Context.user() required User user,
/// }) async {
/// print('Hello, ${user.displayName}!');
/// }
/// ```
const factory Context.user() = _ContextKey.user;
}

final class _ContextKey extends Context {
const _ContextKey._(this.key) : super._();

const _ContextKey.user() : this._('user');

final String key;
}
6 changes: 0 additions & 6 deletions packages/celest/lib/src/core/project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@ class Project implements CloudWidget {
/// {@macro celest.core.project}
const Project({
required this.name,
this.logoUrl,
});

/// The name of the project as its identified in your Celest backend.
final String name;

/// The hosted URL of your project's logo.
///
/// This is used by widgets like [Auth] to craft a custom login page.
final String? logoUrl;
}
40 changes: 40 additions & 0 deletions packages/celest/lib/src/grants/grants.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:celest/src/core/entity.dart';

/// A grant which provides access to all authenticated users.
///
/// ## Example
///
/// ```dart
/// import 'package:celest/celest.dart';
///
/// @authenticated
/// Future<void> sayHello() async {
/// print('User is authenticated!');
/// }
/// ```
const authenticated = _Authenticated();

final class _Role implements Entity {
const _Role({
required this.name,
});

static const _Role authenticated = _Role(name: r'$authenticated');

final String name;
}

/// An assignment which grants a set of permissions to a specific group of
/// [Entity]s.
final class _Grant {
const _Grant({
required this.to,
});

/// The group of [Entity] which are granted access.
final List<Entity> to;
}

final class _Authenticated extends _Grant {
const _Authenticated() : super(to: const [_Role.authenticated]);
}

0 comments on commit 8c5a43b

Please sign in to comment.