This commit is contained in:
@@ -13,6 +13,7 @@ import 'package:repertory/screens/auth_screen.dart';
|
|||||||
import 'package:repertory/screens/edit_mount_screen.dart';
|
import 'package:repertory/screens/edit_mount_screen.dart';
|
||||||
import 'package:repertory/screens/edit_settings_screen.dart';
|
import 'package:repertory/screens/edit_settings_screen.dart';
|
||||||
import 'package:repertory/screens/home_screen.dart';
|
import 'package:repertory/screens/home_screen.dart';
|
||||||
|
import 'package:repertory/widgets/auth_check.dart';
|
||||||
import 'package:sodium_libs/sodium_libs.dart' show SodiumInit;
|
import 'package:sodium_libs/sodium_libs.dart' show SodiumInit;
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
@@ -113,29 +114,3 @@ class _MyAppState extends State<MyApp> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AuthCheck extends StatelessWidget {
|
|
||||||
final Widget child;
|
|
||||||
const AuthCheck({super.key, required this.child});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Consumer<Auth>(
|
|
||||||
builder: (context, auth, _) {
|
|
||||||
if (!auth.authenticated) {
|
|
||||||
Future.delayed(Duration(milliseconds: 1), () {
|
|
||||||
if (constants.navigatorKey.currentContext == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Navigator.of(
|
|
||||||
constants.navigatorKey.currentContext!,
|
|
||||||
).pushNamedAndRemoveUntil('/auth', (Route<dynamic> route) => false);
|
|
||||||
});
|
|
||||||
return child;
|
|
||||||
}
|
|
||||||
|
|
||||||
return child;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
32
web/repertory/lib/widgets/auth_check.dart
Normal file
32
web/repertory/lib/widgets/auth_check.dart
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
// auth_check.dart
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:repertory/constants.dart' as constants;
|
||||||
|
import 'package:repertory/models/auth.dart';
|
||||||
|
|
||||||
|
class AuthCheck extends StatelessWidget {
|
||||||
|
final Widget child;
|
||||||
|
const AuthCheck({super.key, required this.child});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Consumer<Auth>(
|
||||||
|
builder: (context, auth, _) {
|
||||||
|
if (!auth.authenticated) {
|
||||||
|
Future.delayed(Duration(milliseconds: 1), () {
|
||||||
|
if (constants.navigatorKey.currentContext == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Navigator.of(
|
||||||
|
constants.navigatorKey.currentContext!,
|
||||||
|
).pushNamedAndRemoveUntil('/auth', (Route<dynamic> route) => false);
|
||||||
|
});
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
|
return child;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user