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