This commit is contained in:
VE10-Sanjeev 2025-05-22 08:53:43 +00:00
parent a4e32596c2
commit e387bd783c

View File

@ -1,4 +1,6 @@
import 'dart:convert';
import 'dart:html' as html;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:frontend/config/apiUrl.dart';
@ -709,7 +711,9 @@ class _LoginWidgetState extends State<LoginWidget> {
children: [
Expanded(
child: ElevatedButton(
onPressed: () => (),
onPressed: () {
handleMS();
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white, // Button color
foregroundColor: Colors.black, // Text color
@ -815,4 +819,56 @@ class _LoginWidgetState extends State<LoginWidget> {
),
);
}
Future<void> handleMS() async {
final url = '$apiUrl/auth/mslogin';
print(url);
try {
final response = await http.get(
Uri.parse(url),
headers: { 'Content-Type': 'application/json' }
);
print("inside try method");
if (response.statusCode == 200) {
final authUrl = json.decode(response.body)['auth_url'];
print("authurl - $authUrl");
if(authUrl != ''){
// final prefs = await SharedPreferences.getInstance();
// await prefs.setString('auth_token', authUrl);
print('i have auth URL');
// canLaunchUrl(authUrl);
if (kIsWeb) {
print("kIsWeb");
// Use web redirect (e.g., via JS interop or window.location.href)
// redirectTo(url);
html.window.location.href = authUrl;
} else {
// For mobile/desktop, open in external browser
// launchUrl(Uri.parse(url),
// mode: LaunchMode.externalApplication);
}
// final result = await FlutterWebAuth.authenticate(
// url: authUrl,
// callbackUrlScheme: "myapp", // Use a custom scheme you registered
// );
}else{
print('auth URL not Founded');
throw Exception('auth URL not Founded');
}
}else{
final errorMessage = json.decode(response.body)['message'];
print(errorMessage);
throw Exception(errorMessage);
}
}
catch (e) {
print("Error: $e");
}
}
}