Microsoft Login Integration

This commit is contained in:
venbaittech 2025-05-22 15:55:23 +05:30
parent 7b515573c7
commit 00441fe907

View File

@ -23,6 +23,7 @@ import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_quill/flutter_quill.dart' hide Text;
import 'dart:html' as html;
import 'package:frontend/config/apiUrl.dart'; // 1 newly added
import 'package:go_router/go_router.dart';
import 'package:http/http.dart' as http; // 2 newly added
import 'dart:convert'; // 3 newly added
@ -53,51 +54,50 @@ class _MyAppState extends State<MyApp> {
// print(">>> _isAuthRedirect: $_isAuthRedirect");
print(">>> Auth code found at startup: $_authCode");
// You can now:
// - call an API
// - store this in a Provider
// - or just pass it through GoRouter as usual
// if(_authCode){
WidgetsBinding.instance.addPostFrameCallback((_) {
handleTokenUsingMS(_authCode);
// }else{
// _isAuthRedirect = false;
// }
});
}
}
}
Future<void> handleTokenUsingMS(_authCode) async {
Future<void> handleTokenUsingMS(authCode) async {
if (authCode == null) return;
final url = '$apiUrl/auth/auth/verifyMSAuthUser?code=$_authCode';
final url = '$apiUrl/auth/verifyMSAuthUser?code=$authCode';
try {
final response = await http.get(
Uri.parse(url),
headers: { 'Content-Type': 'application/json' }
);
final response = await http
.get(Uri.parse(url), headers: {'Content-Type': 'application/json'});
if (response.statusCode == 200) {
final MS_Token = json.decode(response.body)['token'];
print("MS_Token - $MS_Token");
if(MS_Token != ''){
if (MS_Token != '') {
print('Microsoft - Token Available');
await storeUserDetails(MS_Token);
}else{
print("userRole - $userRole");
if (userRole == "Travel Agent") {
router.go('/listTravelAgentPlan');
} else if (userRole == "Org Admin" || userRole == "Travel Admin") {
router.go('/listAllPlan');
} else {
router.go('/listPlan');
}
} else {
print('Microsoft - Token Not Available');
throw Exception('Token not Founded');
}
}else{
} else {
final errorMessage = json.decode(response.body)['message'];
print(errorMessage);
throw Exception(errorMessage);
}
}
catch (e) {
} catch (e) {
print("Error: $e");
}
}
Future<void> storeUserDetails(String token) async {