Skip to content

Commit

Permalink
[feat] token 발급 #28
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryuuhj committed Mar 15, 2023
1 parent 66f3e9b commit 3017919
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions frontend/lib/screens/home_screen/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:leturn/api/google_signin_api.dart';
import 'package:leturn/const/colors.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:http/http.dart' as http;
import 'package:leturn/screens/page_view.dart';
import 'package:leturn/screens/login/login_page.dart';
import 'package:leturn/screens/user_folder.dart';

import '../../const/Server.dart';

var token;

class HomeScreen extends StatelessWidget{
const HomeScreen({Key? key}) : super(key: key);
Expand Down Expand Up @@ -92,7 +99,12 @@ class _Buttons extends StatelessWidget{
)
],
),
onPressed: signIn,
onPressed: () async {
//bool result = nextPage();
if(await nextPage()) {
Navigator.push(context, MaterialPageRoute(builder: (context) => FolderPage()));
}
},
),
),
//2. 카카오 로그인
Expand Down Expand Up @@ -141,13 +153,34 @@ class _Buttons extends StatelessWidget{
final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
final GoogleSignInAuthentication? googleAuth = await googleUser?.authentication;

if(googleAuth == null){
print("auth is null");
if(googleAuth == null) {
print("google login error >>> googleAuth is null");
}else{
var acct = googleAuth!.accessToken;
print("success: ${acct.toString()}");
String url = '$serverHttp/login/google';
//final req = jsonEncode(<String,String>{'access_token':googleAuth!.accessToken.toString()});
final req = jsonEncode(<String,String>{'access_token':'accessToken'});

http.Response response = await http.post(Uri.parse(url),body: req);

if(response.statusCode == 200){
token = jsonDecode(response.body)["token"];
print("token : $token");
//저장소에 토큰 저장
}else{
print(response.statusCode.toString());
}
}

}

Future<bool> nextPage() async{
await signIn();
if(token == null){
return false;
}else{
return true;
}
}


}

0 comments on commit 3017919

Please sign in to comment.