remove google and facebook auth

This commit is contained in:
Valentin CZERYBA 2025-03-06 20:21:59 +01:00
parent c936a02836
commit 7f3240242d
3 changed files with 1 additions and 103 deletions

View File

@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
flutter.compileSdkVersion=35

View File

@ -1,14 +1,10 @@
import 'dart:convert'; import 'dart:convert';
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import '../variable/globals.dart' as globals; import '../variable/globals.dart' as globals;
import 'dart:io'; import 'dart:io';
class AuthService { class AuthService {
final GoogleSignIn _googleSignIn = GoogleSignIn();
// Login with username and password // Login with username and password
Future<bool> login(String username, String password) async { Future<bool> login(String username, String password) async {
final url = Uri.parse("${globals.api}/token"); final url = Uri.parse("${globals.api}/token");
@ -53,7 +49,6 @@ class AuthService {
Future<void> logout() async { Future<void> logout() async {
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();
await prefs.remove("access_token"); await prefs.remove("access_token");
await _googleSignIn.signOut();
} }
Future<bool> isLoggedIn() async { Future<bool> isLoggedIn() async {
@ -97,56 +92,5 @@ class AuthService {
return prefs.getString("access_token"); return prefs.getString("access_token");
} }
// Login with Facebook
Future<String?> signInWithFacebook() async {
try {
final LoginResult result = await FacebookAuth.instance.login();
if (result.status == LoginStatus.success && result.accessToken != null) {
final AccessToken? accessToken = result.accessToken;
final response = await http.post(
Uri.parse("${globals.api}/auth/facebook"),
headers: {"Content-Type": "application/json"},
body: jsonEncode({"token": accessToken!.tokenString}),
);
if (response.statusCode == 200) {
final data = json.decode(response.body);
final prefs = await SharedPreferences.getInstance();
prefs.setString("access_token", data["access_token"]);
return data["access_token"];
}
}
} catch (e) {
print("Facebook login error: $e");
}
return null;
}
// Login with Google // Login with Google
Future<String?> signInWithGoogle() async {
try {
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
if (googleUser == null) return null; // User canceled login
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final response = await http.post(
Uri.parse("${globals.api}/auth/google"),
headers: {"Content-Type": "application/json"},
body: jsonEncode({"token": googleAuth.idToken}),
);
if (response.statusCode == 200) {
final data = json.decode(response.body);
final prefs = await SharedPreferences.getInstance();
prefs.setString("access_token", data["access_token"]);
return data["access_token"];
}
} catch (e) {
print("Google login error: $e");
}
return null;
}
} }

View File

@ -39,26 +39,6 @@ class _LoginDemoState extends State<LoginDemo> with ShowAlertDialog {
} }
} }
Future<void> _loginWithFacebook(BuildContext context) async {
String? token = await _authService.signInWithFacebook();
if (token != null) {
Navigator.push(
context, MaterialPageRoute(builder: (_) => ListItemMenu()));
} else {
showAlertDialog(context, "Erreur", "Échec de la connexion Facebook");
}
}
Future<void> _loginWithGoogle(BuildContext context) async {
String? token = await _authService.signInWithGoogle();
if (token != null) {
Navigator.push(
context, MaterialPageRoute(builder: (_) => ListItemMenu()));
} else {
showAlertDialog(context, "Erreur", "Échec de la connexion Google");
}
}
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -149,33 +129,6 @@ class _LoginDemoState extends State<LoginDemo> with ShowAlertDialog {
style: TextStyle(color: Colors.white, fontSize: 25)), style: TextStyle(color: Colors.white, fontSize: 25)),
), ),
), ),
SizedBox(height: 20),
Container(
height: 50,
width: 250,
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.circular(20)),
child: TextButton(
onPressed: () => _loginWithFacebook(context),
child: Text('Login with Facebook',
style: TextStyle(color: Colors.white, fontSize: 20)),
),
),
SizedBox(height: 20),
// Google Login Button
Container(
height: 50,
width: 250,
decoration: BoxDecoration(
color: Colors.redAccent,
borderRadius: BorderRadius.circular(20)),
child: TextButton(
onPressed: () => _loginWithGoogle(context),
child: Text('Login with Google',
style: TextStyle(color: Colors.white, fontSize: 20)),
),
),
SizedBox(height: 130), SizedBox(height: 130),
InkWell( InkWell(
child: Text('New User? Create Account'), child: Text('New User? Create Account'),