Skip to content

Commit

Permalink
Fixing shared preferences Secure Profile
Browse files Browse the repository at this point in the history
  • Loading branch information
kaenova committed Jun 16, 2022
1 parent 4181b91 commit f0beadb
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion mobile/lib/api/review.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Future<void> createReview(
if (e.response != null) {
var response = e.response!;
if (response.statusCode == 401) {
profile.setLoggedOut();
await profile.setLoggedOut();
return Future.error("Session expired");
}
if (response.statusCode == 400) {
Expand Down
6 changes: 3 additions & 3 deletions mobile/lib/api/tikum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Future<List<TikumProfile>> getMyTikum() async {
);

if (response.statusCode == 401) {
profile.setLoggedOut();
await profile.setLoggedOut();
return Future.error("Session expired");
}

Expand Down Expand Up @@ -64,7 +64,7 @@ Future<void> deleteMyTikum(int id) async {
);

if (response.statusCode == 401) {
profile.setLoggedOut();
await profile.setLoggedOut();
return Future.error("Session expired");
}

Expand Down Expand Up @@ -106,7 +106,7 @@ Future<void> createTikum({
if (e.response != null) {
var response = e.response!;
if (response.statusCode == 401) {
profile.setLoggedOut();
await profile.setLoggedOut();
return Future.error("Session expired");
}
if (response.statusCode == 400) {
Expand Down
12 changes: 6 additions & 6 deletions mobile/lib/api/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Future<void> loginUser(String email, String password) async {
var id = decoded["user"]["id"];

var profile = await SecureProfile.getStorage();
profile.setLoggedIn(id, token);
await profile.setLoggedIn(id, token);
} else if (response.statusCode == 400) {
return Future.error("Email atau password salah");
} else {
Expand Down Expand Up @@ -59,7 +59,7 @@ Future<List<ReviewProfile>> getMyReviewById() async {
);

if (response.statusCode == 401) {
profile.setLoggedOut();
await profile.setLoggedOut();
return Future.error("Session expired, please login again");
}

Expand Down Expand Up @@ -88,7 +88,7 @@ Future<Profile> getMyProfileById() async {
);

if (response.statusCode == 401) {
profile.setLoggedOut();
await profile.setLoggedOut();
return Future.error("Session expired, please login again");
}

Expand Down Expand Up @@ -118,7 +118,7 @@ Future<void> deleteMyReview(int id) async {
);

if (response.statusCode == 401) {
profile.setLoggedOut();
await profile.setLoggedOut();
return Future.error("Session expired, please login again");
}

Expand All @@ -144,15 +144,15 @@ Future<void> userLogout() async {
);

if (res.statusCode == 401) {
profile.setLoggedOut();
await profile.setLoggedOut();
return Future.error("Session expired, please login again");
}

if (res.statusCode != 200) {
return Future.error("Failed to logout");
}

profile.setLoggedOut();
await profile.setLoggedOut();
}

Future<Profile> getUserProfileById(int id) async {
Expand Down
4 changes: 2 additions & 2 deletions mobile/lib/model/profile_secure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ class SecureProfile {
return userId;
}

void setLoggedIn(int userId, String apiKey) async {
Future<void> setLoggedIn(int userId, String apiKey) async {
await storage.setInt("user_id", userId);
await storage.setString("api_key", apiKey);
isLoggedIn = true;
}

void setLoggedOut() async {
Future<void> setLoggedOut() async {
await storage.remove("api_key");
await storage.remove("user_id");
isLoggedIn = false;
Expand Down
1 change: 0 additions & 1 deletion mobile/lib/screen/home/components/tikum/tikum.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:mobile/model/profile_secure.dart';
import 'package:mobile/screen/form_tikum/form_tikum_screen.dart';
import 'package:mobile/screen/test_screen/test_screen.dart';
import 'package:mobile/screen/home/components/tikum/global_tikum.dart';
import 'package:mobile/screen/home/components/tikum/my_tikum.dart';

Expand Down
4 changes: 2 additions & 2 deletions mobile/lib/screen/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HomeScreen extends StatefulWidget {
class _HomeScreenState extends State<HomeScreen> {
final List<Widget> section = [
const Timeline(),
TikumLayout(),
const TikumLayout(),
ProfileSection()
];
var sectionidx = 0;
Expand All @@ -34,7 +34,7 @@ class _HomeScreenState extends State<HomeScreen> {

return Scaffold(
appBar: AppBar(
actions: [Image(image: AssetImage("assets/Logos.png"))],
actions: const [Image(image: AssetImage("assets/Logos.png"))],
title: const Text("Travelliu",
style: TextStyle(fontWeight: FontWeight.bold)),
backgroundColor: Colors.white,
Expand Down

0 comments on commit f0beadb

Please sign in to comment.