diff --git a/packages/dox-app/db/migration/2023_07_16_131937700_create_user_table.sql b/packages/dox-app/db/migration/2023_07_16_131937700_create_user_table.sql index fc6200a..0395319 100644 --- a/packages/dox-app/db/migration/2023_07_16_131937700_create_user_table.sql +++ b/packages/dox-app/db/migration/2023_07_16_131937700_create_user_table.sql @@ -2,7 +2,7 @@ CREATE TABLE IF NOT EXISTS users ( id serial PRIMARY KEY, name VARCHAR ( 255 ) NOT NULL, - email VARCHAR ( 255 ) NOT NULL, + email VARCHAR ( 255 ) UNIQUE NOT NULL, password VARCHAR ( 255 ) NOT NULL, deleted_at TIMESTAMP, created_at TIMESTAMP, diff --git a/packages/dox-app/lib/config/auth_config.dart b/packages/dox-app/lib/config/auth_config.dart deleted file mode 100644 index 3341107..0000000 --- a/packages/dox-app/lib/config/auth_config.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:dox_app/models/user/user.model.dart'; -import 'package:dox_auth/dox_auth.dart'; -import 'package:dox_core/dox_core.dart'; - -class AuthConfig extends IAuthConfig { - @override - String get defaultGuard => 'web'; - - @override - Map get guards => { - 'web': AuthGuard( - driver: JwtAuthDriver( - secret: SecretKey(Env.get('APP_KEY')), - ), - provider: AuthProvider( - model: () => User(), - ), - ), - }; -} diff --git a/packages/dox-app/lib/services/auth_service.dart b/packages/dox-app/lib/services/auth_service.dart index 2a7b50b..7728f23 100644 --- a/packages/dox-app/lib/services/auth_service.dart +++ b/packages/dox-app/lib/services/auth_service.dart @@ -1,10 +1,23 @@ -import 'package:dox_app/config/auth_config.dart'; +import 'package:dox_app/models/user/user.model.dart'; import 'package:dox_auth/dox_auth.dart'; import 'package:dox_core/dox_core.dart'; class AuthService implements DoxService { @override void setup() { - Auth.initialize(AuthConfig()); + Auth.initialize(AuthConfig( + /// default auth guard + defaultGuard: 'web', + + /// list of auth guards + guards: { + 'web': AuthGuard( + driver: JwtAuthDriver(secret: SecretKey(Env.get('APP_KEY'))), + provider: AuthProvider( + model: () => User(), + ), + ), + }, + )); } } diff --git a/packages/dox-auth/lib/src/auth.dart b/packages/dox-auth/lib/src/auth.dart index 0a4ceb1..0348521 100644 --- a/packages/dox-auth/lib/src/auth.dart +++ b/packages/dox-auth/lib/src/auth.dart @@ -9,7 +9,7 @@ class Auth implements IAuth { AuthDriver get _driver => AuthEngine().driver; - static void initialize(IAuthConfig authConfig) { + static void initialize(AuthConfig authConfig) { AuthEngine().init(authConfig); } diff --git a/packages/dox-auth/lib/src/auth_engine.dart b/packages/dox-auth/lib/src/auth_engine.dart index dbe6c31..dc5e507 100644 --- a/packages/dox-auth/lib/src/auth_engine.dart +++ b/packages/dox-auth/lib/src/auth_engine.dart @@ -1,7 +1,7 @@ import 'package:dox_auth/src/interfaces.dart'; class AuthEngine { - late IAuthConfig config; + late AuthConfig config; /// get auth guard AuthGuard get guard => config.guards[config.defaultGuard]!; @@ -17,7 +17,7 @@ class AuthEngine { factory AuthEngine() => _singleton; AuthEngine._internal(); - void init(IAuthConfig authConfig) { + void init(AuthConfig authConfig) { config = authConfig; } } diff --git a/packages/dox-auth/lib/src/interfaces.dart b/packages/dox-auth/lib/src/interfaces.dart index 44744c6..abc12fa 100644 --- a/packages/dox-auth/lib/src/interfaces.dart +++ b/packages/dox-auth/lib/src/interfaces.dart @@ -23,10 +23,14 @@ class AuthProvider { }); } -abstract class IAuthConfig { - String get defaultGuard => 'web'; +class AuthConfig { + final String defaultGuard; + final Map guards; - Map get guards => {}; + AuthConfig({ + required this.defaultGuard, + this.guards = const {}, + }); } abstract class AuthDriver {