Add auth session flow and sign-in UX
This commit is contained in:
@@ -1,13 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:relationship_saver/core/config/app_config.dart';
|
||||
import 'package:relationship_saver/core/config/app_theme.dart';
|
||||
import 'package:relationship_saver/features/auth/session_controller.dart';
|
||||
import 'package:relationship_saver/features/shared/frosted_card.dart';
|
||||
import 'package:relationship_saver/integrations/backend/models/backend_models.dart';
|
||||
|
||||
class SettingsView extends StatelessWidget {
|
||||
class SettingsView extends ConsumerWidget {
|
||||
const SettingsView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final AuthSession? session = ref
|
||||
.watch(sessionControllerProvider)
|
||||
.asData
|
||||
?.value;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(28, 24, 28, 28),
|
||||
child: Column(
|
||||
@@ -26,6 +34,14 @@ class SettingsView extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
_SettingRow(
|
||||
label: 'Signed in as',
|
||||
value:
|
||||
session?.user.email ??
|
||||
session?.user.id ??
|
||||
'Not signed in',
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_SettingRow(
|
||||
label: 'Gateway mode',
|
||||
value: AppConfig.useFakeBackend
|
||||
@@ -39,6 +55,30 @@ class SettingsView extends StatelessWidget {
|
||||
label: 'Realtime',
|
||||
value: 'Planned later (SSE/WebSocket)',
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
FilledButton.icon(
|
||||
onPressed: session == null
|
||||
? null
|
||||
: () => _signOut(context, ref),
|
||||
icon: const Icon(Icons.logout_rounded),
|
||||
label: const Text('Sign Out'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
OutlinedButton.icon(
|
||||
onPressed: session == null
|
||||
? null
|
||||
: () {
|
||||
ref
|
||||
.read(sessionControllerProvider.notifier)
|
||||
.refreshProfile();
|
||||
},
|
||||
icon: const Icon(Icons.refresh_rounded),
|
||||
label: const Text('Refresh Profile'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -53,6 +93,15 @@ class SettingsView extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _signOut(BuildContext context, WidgetRef ref) async {
|
||||
await ref.read(sessionControllerProvider.notifier).signOut();
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('Signed out.')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _SettingRow extends StatelessWidget {
|
||||
|
||||
Reference in New Issue
Block a user