Skip to content

Commit

Permalink
feat(logout): added button to logout in the dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
sambrus committed Dec 9, 2024
1 parent 375f0d0 commit 01d5baa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
21 changes: 16 additions & 5 deletions client_mobile/lib/pages/dashboard/dashboard.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:client_mobile/services/login/auth_service.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

class DashboardPage extends StatefulWidget {
const DashboardPage({super.key});
Expand All @@ -10,10 +12,19 @@ class DashboardPage extends StatefulWidget {
class _DashboardPageState extends State<DashboardPage> {
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: Text("Dashboard ")
)
return Scaffold(
body: const Center(
child: Text("Dashboard "),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
bool hasLogout = await AuthService.logout();
if (hasLogout)
context.pushReplacement("/login");
},
tooltip: 'Logout',
child: const Icon(Icons.login),
),
);
}
}
}
10 changes: 10 additions & 0 deletions client_mobile/lib/services/login/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,14 @@ class AuthService {
return (false);
}
}

static Future<bool> logout() async {
bool isLogin = await secureStorage.read(key: "bearer_token") != null;

if (isLogin) {
await secureStorage.delete(key: "bearer_token");
return (true);
}
return (false);
}
}

0 comments on commit 01d5baa

Please sign in to comment.