Skip to content

Commit

Permalink
[login] fixed no redirect after just logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed May 5, 2024
1 parent 4f1f74f commit 598e0bf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/credentials/storage/credential.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CredentialStorage {

late final $oaLastAuthTime = box.provider<DateTime>(_OaK.lastAuthTime);

LoginStatus? get oaLoginStatus => box.safeGet<LoginStatus>(_OaK.loginStatus);
LoginStatus? get oaLoginStatus => box.safeGet<LoginStatus>(_OaK.loginStatus) ?? LoginStatus.never;

set oaLoginStatus(LoginStatus? newV) => box.safePut<LoginStatus>(_OaK.loginStatus, newV);

Expand Down
4 changes: 2 additions & 2 deletions lib/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import 'package:sit/timetable/page/edit/editor.dart';
import 'package:sit/timetable/page/p13n/palette_editor.dart';
import 'package:sit/timetable/page/patch/patch.dart';
import 'package:sit/timetable/page/settings.dart';
import 'package:sit/utils/riverpod.dart';
import 'package:sit/widgets/not_found.dart';
import 'package:sit/school/oa_announce/entity/announce.dart';
import 'package:sit/school/oa_announce/page/details.dart';
Expand Down Expand Up @@ -92,7 +91,8 @@ String? _loginRequired(BuildContext ctx, GoRouterState state) {
}

FutureOr<String?> _redirectRoot(BuildContext ctx, GoRouterState state) {
final loginStatus = ctx.riverpod().read(CredentialsInit.storage.$oaLoginStatus);
// `ctx.riverpod().read(CredentialsInit.storage.$oaLoginStatus)` would return `LoginStatus.never` after just logged in.
final loginStatus = CredentialsInit.storage.oaLoginStatus;
if (loginStatus == LoginStatus.never) {
// allow to access settings page.
if (state.matchedLocation.startsWith("/tools")) return null;
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/hive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ extension BoxProviderX on Box {
}) {
return StateNotifierProvider<BoxFieldWithDefaultNotifier<T>, T>((ref) {
return BoxFieldWithDefaultNotifier(
get?.call() ?? safeGet<T>(key) ?? getDefault(),
(get != null ? get.call() : safeGet<T>(key)) ?? getDefault(),
listenable(keys: [key]),
() => get != null ? get.call() : safeGet<T>(key),
(v) => set != null ? set.call(v) : safePut<T>(key, v),
Expand Down

0 comments on commit 598e0bf

Please sign in to comment.