step 5 : add public key, login try using public and failed
This commit is contained in:
@@ -1,31 +1,75 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import '../../app/constant.dart';
|
||||
import '../../provider/google_login_provider.dart';
|
||||
|
||||
import 'package:crypton/crypton.dart' as crypton;
|
||||
|
||||
class LoginScreen extends HookConsumerWidget {
|
||||
const LoginScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
|
||||
// inisialisasi
|
||||
// ref.watch itu sama spt memantau state terus menerus
|
||||
// ref.read itu memantau namun hny 1x saja
|
||||
GoogleSignInAccount? currentUser = ref.watch(currentUserProvider);
|
||||
final googleSignIn = ref.watch(googleSignInProvider);
|
||||
|
||||
Future<void> postPublicKey() async {
|
||||
Dio dio = Dio();
|
||||
String url = "https://example.com/api/post_endpoint";
|
||||
try {
|
||||
final publicPem = await rootBundle.loadString('assets/public_key.pem');
|
||||
final publicKey = crypton.RSAPublicKey.fromPEM(publicPem);
|
||||
|
||||
// GoogleSignInAccount? currentUser = ref.watch(currentUserProvider);
|
||||
// final googleSignIn = ref.watch(googleSignInProvider);
|
||||
// return filePath;
|
||||
|
||||
publicKey.encrypt("testing satu dua tiga");
|
||||
Map<String, dynamic> data = {
|
||||
"publickey": publicKey,
|
||||
"id_google_sign_in": "102110797605607117832",
|
||||
"email": "sindhu@sismedia.com"
|
||||
};
|
||||
|
||||
Response response = await dio.post(
|
||||
url,
|
||||
data: data,
|
||||
);
|
||||
|
||||
// Menampilkan respons dari server
|
||||
print("Response data: ${response.data}");
|
||||
|
||||
// googleSignIn.onCurrentUserChanged.listen((account) {
|
||||
// // untuk update value ke provider google_login_provider yaitu currentUserProvider
|
||||
// ref.read(currentUserProvider.notifier).update((state) => account);
|
||||
// });
|
||||
// googleSignIn.signInSilently();
|
||||
} catch (e) {
|
||||
print("Error reading file: $e");
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() {
|
||||
googleSignIn.onCurrentUserChanged.listen((account) {
|
||||
// untuk update value ke provider google_login_provider yaitu currentUserProvider
|
||||
ref.read(currentUserProvider.notifier).update((state) => account);
|
||||
});
|
||||
googleSignIn.signInSilently();
|
||||
return (){};
|
||||
// googleSignIn.onCurrentUserChanged.listen((account) {
|
||||
// // untuk update value ke provider google_login_provider yaitu currentUserProvider
|
||||
// ref.read(currentUserProvider.notifier).update((state) => account);
|
||||
// });
|
||||
// googleSignIn.signInSilently();
|
||||
|
||||
postPublicKey();
|
||||
return () {};
|
||||
}, const []);
|
||||
|
||||
// fungsi untuk sync ke google mail
|
||||
@@ -47,7 +91,7 @@ class LoginScreen extends HookConsumerWidget {
|
||||
SizedBox(
|
||||
height: Constant.getActualYPhone(context: context, y: 100),
|
||||
),
|
||||
(currentUser != null)
|
||||
(currentUser != null)
|
||||
? Container(
|
||||
child: ListTile(
|
||||
leading: GoogleUserCircleAvatar(
|
||||
|
||||
Reference in New Issue
Block a user