Skip to content

Commit

Permalink
Merge pull request #30 from Fam-Story/refactor/29-refactor-가족-여부에-따른-…
Browse files Browse the repository at this point in the history
…라우트-수정

♻️ Refactor: 페이지 라우트 로직 수정(#29)
  • Loading branch information
frankwon11 authored Nov 24, 2023
2 parents 866743d + 9a70593 commit 483a2d5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/screens/loading_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';

import 'package:fam_story_frontend/pages/family_join_create_page.dart';
import 'package:fam_story_frontend/services/user_api_service.dart';
import 'package:fam_story_frontend/widgets/loading_indicator.dart';
import 'package:flutter/material.dart';
Expand All @@ -23,18 +24,24 @@ class _LoadingScreenState extends State<LoadingScreen> {
// 로그인 상태 확인
const storage = FlutterSecureStorage();
String? userInfoString = await storage.read(key: 'login');

int? isBelongedFamily;
if (userInfoString != null) {
Map<String, dynamic> userInfo = json.decode(userInfoString);
if (userInfo['email'] != null) {
// 자동 로그인 상태; 토큰 정보 자동으로 다시 받아오기
try {
UserApiService.postUserLogin(userInfo['email'], userInfo['password'], true);
isBelongedFamily = await UserApiService.postUserLogin(userInfo['email'], userInfo['password'], true);
} catch (e) {
// TODO: 에러 팝업 추가
print(e.toString());
}
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const RootPage()));
if (isBelongedFamily == 1) {
// 가족이 있는 경우
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const RootPage()));
} else if (isBelongedFamily == 0) {
// 가족이 없는 경우
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const FamilyJoinCreatePage()));
}
} else {
// 자동 로그인 X
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const LoginSignUpPage()));
Expand Down

0 comments on commit 483a2d5

Please sign in to comment.