Add manual auth screen
This commit is contained in:
4
moneymgr_mobile/lib/services/api/account_api.dart
Normal file
4
moneymgr_mobile/lib/services/api/account_api.dart
Normal file
@ -0,0 +1,4 @@
|
||||
/// Account API
|
||||
class AccountAPI {
|
||||
|
||||
}
|
7
moneymgr_mobile/lib/services/api/api_client.dart
Normal file
7
moneymgr_mobile/lib/services/api/api_client.dart
Normal file
@ -0,0 +1,7 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
/// Client API
|
||||
@riverpod
|
||||
class ClientAPI {
|
||||
|
||||
}
|
16
moneymgr_mobile/lib/services/api/api_token.dart
Normal file
16
moneymgr_mobile/lib/services/api/api_token.dart
Normal file
@ -0,0 +1,16 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'api_token.freezed.dart';
|
||||
part 'api_token.g.dart';
|
||||
|
||||
@freezed
|
||||
abstract class ApiToken with _$ApiToken {
|
||||
const factory ApiToken({
|
||||
required String apiUrl,
|
||||
required int tokenId,
|
||||
required String tokenValue
|
||||
}) = _ApiToken;
|
||||
|
||||
factory ApiToken.fromJson(Map<String, dynamic> json) =>
|
||||
_$ApiTokenFromJson(json);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import 'package:moneymgr_mobile/routes/login/login_model.dart';
|
||||
import 'package:moneymgr_mobile/services/api/api_token.dart';
|
||||
import 'package:moneymgr_mobile/services/router/routes_list.dart';
|
||||
import 'package:moneymgr_mobile/services/storage/secure_storage.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
@ -8,7 +8,7 @@ part 'auth_state.g.dart';
|
||||
/// The current authentication state of the app.
|
||||
///
|
||||
/// This notifier is responsible for saving/removing the token and profile info
|
||||
/// to the storage through the [login] and [logout] methods.
|
||||
/// to the storage through the [setAuthToken] and [logout] methods.
|
||||
@riverpod
|
||||
class CurrentAuthState extends _$CurrentAuthState {
|
||||
@override
|
||||
@ -18,9 +18,9 @@ class CurrentAuthState extends _$CurrentAuthState {
|
||||
return token != null ? AuthState.authenticated : AuthState.unauthenticated;
|
||||
}
|
||||
|
||||
/// Attempts to log in with [data] and saves the token and profile info to storage.
|
||||
/// Attempts to authenticate with [data] and saves the token and profile info to storage.
|
||||
/// Will invalidate the state if success.
|
||||
Future<void> login(LoginModel data) async {
|
||||
Future<void> setAuthToken(ApiToken data) async {
|
||||
// TODO : perform login
|
||||
/*final secureStorage = ref.read(secureStorageProvider).requireValue;
|
||||
final token = await ref.read(apiServiceProvider).login(data);
|
||||
@ -53,13 +53,12 @@ class CurrentAuthState extends _$CurrentAuthState {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// The possible authentication states of the app.
|
||||
enum AuthState {
|
||||
unknown(redirectPath: homePage, allowedPaths: [homePage]),
|
||||
unauthenticated(
|
||||
redirectPath: authPage,
|
||||
allowedPaths: [authPage, settingsPage],
|
||||
allowedPaths: [authPage, manualAuthPage, settingsPage],
|
||||
),
|
||||
authenticated(redirectPath: homePage, allowedPaths: null);
|
||||
|
||||
|
@ -2,13 +2,12 @@ import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:moneymgr_mobile/routes/login/login_screen.dart';
|
||||
import 'package:moneymgr_mobile/routes/login/manual_auth_screen.dart';
|
||||
import 'package:moneymgr_mobile/routes/settings/settings_screen.dart';
|
||||
import 'package:moneymgr_mobile/services/auth_state.dart';
|
||||
import 'package:moneymgr_mobile/services/router/routes_list.dart';
|
||||
import 'package:moneymgr_mobile/widgets/scaffold_with_navigation.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
|
||||
part 'router.g.dart';
|
||||
|
||||
/// The router config for the app.
|
||||
@ -62,9 +61,10 @@ GoRouter router(Ref ref) {
|
||||
GoRoute(path: homePage, builder: (_, __) => const Scaffold()),
|
||||
GoRoute(path: authPage, builder: (_, __) => const LoginScreen()),
|
||||
GoRoute(
|
||||
path: settingsPage,
|
||||
builder: (_, __) => const SettingsScreen(),
|
||||
path: manualAuthPage,
|
||||
builder: (_, __) => const ManualAuthScreen(),
|
||||
),
|
||||
GoRoute(path: settingsPage, builder: (_, __) => const SettingsScreen()),
|
||||
|
||||
// Configuration for the bottom navigation bar routes. The routes themselves
|
||||
// should be defined in [navigationItems]. Modification to this [ShellRoute]
|
||||
|
Reference in New Issue
Block a user