28 lines
825 B
Dart
28 lines
825 B
Dart
import 'package:http/http.dart' as http;
|
|
import 'dart:convert';
|
|
|
|
class AuthService {
|
|
final String baseUrl = 'https://group-10-15.pvt.dsv.su.se/';
|
|
|
|
Future<void> signInWithGoogle() async {
|
|
final url = Uri.parse('$baseUrl/auth/google'); //vet ej URL än
|
|
|
|
try {
|
|
final response = await http.get(url); // eller POST?
|
|
|
|
if (response.statusCode == 200) {
|
|
final data = json.decode(response.body);
|
|
|
|
final token = data['token']; //beror på vad vi får tillbaka från backend, token el bool?
|
|
print('Login lyckades! Token: $token'); //bara test
|
|
|
|
} else {
|
|
print('Fel vid inloggning: ${response.statusCode}');
|
|
throw Exception('Inloggning misslyckades');
|
|
}
|
|
} catch (e) {
|
|
print('Fel vid anrop till backend: $e');
|
|
rethrow;
|
|
}
|
|
}
|
|
} |