Microsoft Login Integration
This commit is contained in:
parent
7b515573c7
commit
00441fe907
38
lib/app.dart
38
lib/app.dart
@ -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,29 +54,20 @@ 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'];
|
||||||
@ -84,6 +76,16 @@ class _MyAppState extends State<MyApp> {
|
|||||||
if (MS_Token != '') {
|
if (MS_Token != '') {
|
||||||
print('Microsoft - Token Available');
|
print('Microsoft - Token Available');
|
||||||
await storeUserDetails(MS_Token);
|
await storeUserDetails(MS_Token);
|
||||||
|
|
||||||
|
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 {
|
} else {
|
||||||
print('Microsoft - Token Not Available');
|
print('Microsoft - Token Not Available');
|
||||||
throw Exception('Token not Founded');
|
throw Exception('Token not Founded');
|
||||||
@ -93,11 +95,9 @@ class _MyAppState extends State<MyApp> {
|
|||||||
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 {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user