FORBIDEN REFRESH HANDLING
This commit is contained in:
parent
bd7d538481
commit
52878d6810
@ -157,6 +157,9 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||
final token = data['token']; // Assuming the token is in response
|
||||
// final userId = data['user_id'].toString();
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
prefs.clear();
|
||||
print("CLEARINGGG-- ");
|
||||
print("Token - $token");
|
||||
await storeUserDetails(token);
|
||||
|
||||
|
||||
@ -263,9 +263,10 @@ class _groupState extends State<Group> {
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
print("GRPDATA");
|
||||
await apiService.handleTokenRefresh(context, userId!);
|
||||
|
||||
print("Group submitted successfully!");
|
||||
print("Response: ${response.body}");
|
||||
await apiService.handleTokenRefresh(context, userId!);
|
||||
context.go('/group');
|
||||
} else if (response.statusCode == 403) {
|
||||
print("403-FORB");
|
||||
|
||||
@ -284,9 +284,9 @@ class GroupDataState extends State<GroupData> {
|
||||
print("Response: ${response.body}");
|
||||
// _clearError();
|
||||
_clearError();
|
||||
await apiService.handleTokenRefresh(context, userId!);
|
||||
await widget.fetchGetGroup();
|
||||
|
||||
await apiService.handleTokenRefresh(context, userId!);
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop(); // Close modal only if mounted
|
||||
}
|
||||
@ -295,11 +295,6 @@ class GroupDataState extends State<GroupData> {
|
||||
});
|
||||
|
||||
// dispose();
|
||||
} else if (response.statusCode == 403) {
|
||||
print("403-FORB");
|
||||
await apiService.logout(context);
|
||||
return null;
|
||||
// throw Exception('Failed to load users');
|
||||
} else if (response.statusCode == 404) {
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
@ -384,7 +384,7 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
print("✅ User submitted successfully!");
|
||||
print("📨 Response Organizt Update: ${response.body}");
|
||||
|
||||
await apiService.handleTokenRefresh(context, userId!);
|
||||
final data = json.decode(response.body);
|
||||
|
||||
if (!data.containsKey('data') || data['data'] is! Map) {
|
||||
@ -400,7 +400,7 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
|
||||
print(orgList);
|
||||
await updateOrgDataWithNewValues(orgList);
|
||||
await apiService.handleTokenRefresh(context, userId!);
|
||||
|
||||
print("📨 Response Organizt Update:");
|
||||
// return orgList;
|
||||
context.go('/OrganizationSettings');
|
||||
|
||||
@ -851,14 +851,12 @@ class CreateNewPlansState extends State<CreateNewPlan> {
|
||||
} catch (e) {
|
||||
throw Exception('Error parsing response: $e');
|
||||
}
|
||||
}
|
||||
else if (response.statusCode == 403) {
|
||||
} else if (response.statusCode == 403) {
|
||||
print("403-FORB");
|
||||
await apiService.logout(context);
|
||||
return null;
|
||||
// throw Exception('Failed to load users');
|
||||
}
|
||||
else if (response.statusCode == 404) {
|
||||
} else if (response.statusCode == 404) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
@ -1023,14 +1021,12 @@ class CreateNewPlansState extends State<CreateNewPlan> {
|
||||
} catch (e) {
|
||||
throw Exception('Error parsing response: $e');
|
||||
}
|
||||
}
|
||||
else if (response.statusCode == 403) {
|
||||
} else if (response.statusCode == 403) {
|
||||
print("403-FORB");
|
||||
await apiService.logout(context);
|
||||
return null;
|
||||
// throw Exception('Failed to load users');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw Exception('Failed to load plans');
|
||||
}
|
||||
}
|
||||
@ -1102,14 +1098,12 @@ class CreateNewPlansState extends State<CreateNewPlan> {
|
||||
} catch (e) {
|
||||
throw Exception('Error parsing response: $e');
|
||||
}
|
||||
}
|
||||
else if (response.statusCode == 403) {
|
||||
} else if (response.statusCode == 403) {
|
||||
print("403-FORB");
|
||||
await apiService.logout(context);
|
||||
return null;
|
||||
// throw Exception('Failed to load users');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw Exception('Failed to load plans');
|
||||
}
|
||||
}
|
||||
@ -1163,14 +1157,12 @@ class CreateNewPlansState extends State<CreateNewPlan> {
|
||||
} catch (e) {
|
||||
throw Exception('Error parsing response: $e');
|
||||
}
|
||||
}
|
||||
else if (response.statusCode == 403) {
|
||||
} else if (response.statusCode == 403) {
|
||||
print("403-FORB");
|
||||
await apiService.logout(context);
|
||||
return null;
|
||||
// throw Exception('Failed to load users');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw Exception('Failed to load plans');
|
||||
}
|
||||
}
|
||||
@ -1222,14 +1214,12 @@ class CreateNewPlansState extends State<CreateNewPlan> {
|
||||
} catch (e) {
|
||||
throw Exception('Error parsing response: $e');
|
||||
}
|
||||
}
|
||||
else if (response.statusCode == 403) {
|
||||
} else if (response.statusCode == 403) {
|
||||
print("403-FORB");
|
||||
await apiService.logout(context);
|
||||
return null;
|
||||
// throw Exception('Failed to load users');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw Exception('Failed to load plans');
|
||||
}
|
||||
}
|
||||
@ -1384,14 +1374,12 @@ class CreateNewPlansState extends State<CreateNewPlan> {
|
||||
// Close loading dialog (ONLY if still mounted)
|
||||
if (mounted) Navigator.of(context, rootNavigator: true).pop();
|
||||
context.go('/approvallist');
|
||||
}
|
||||
else if (response.statusCode == 403) {
|
||||
} else if (response.statusCode == 403) {
|
||||
print("403-FORB");
|
||||
await apiService.logout(context);
|
||||
return null;
|
||||
// throw Exception('Failed to load users');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
print("$methodName failed. Status: ${response.statusCode}");
|
||||
print("Error: ${response.body}");
|
||||
}
|
||||
@ -1602,14 +1590,12 @@ class CreateNewPlansState extends State<CreateNewPlan> {
|
||||
// ? context.go('/approvallist')
|
||||
// : context.go('/listPlan');
|
||||
// }
|
||||
}
|
||||
else if (response.statusCode == 403) {
|
||||
} else if (response.statusCode == 403) {
|
||||
print("403-FORB");
|
||||
await apiService.logout(context);
|
||||
return null;
|
||||
// throw Exception('Failed to load users');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
print("Failed to submit plan. Status: ${response.statusCode}");
|
||||
print("Error: ${response.body}");
|
||||
|
||||
@ -3375,9 +3361,11 @@ class CreateNewPlansState extends State<CreateNewPlan> {
|
||||
_showInputDialog(selected["title"]!);
|
||||
} else if (_selectedOption == "Option 1") {
|
||||
otherUserName = userName;
|
||||
await apiService.handleTripWiseToken(selfId!, context);
|
||||
// await apiService.handleTripWiseToken(selfId!, context);
|
||||
fetchUserDetails();
|
||||
_selectedTripType = null;
|
||||
getSelectedPlanFor();
|
||||
fetchUsrDtlFromSelectedTripUser();
|
||||
dynamicItineraryKey.currentState
|
||||
?.loadOrgSelectedAlServices();
|
||||
dynamicItineraryKey.currentState
|
||||
@ -3777,7 +3765,7 @@ class CreateNewPlansState extends State<CreateNewPlan> {
|
||||
keyboardType: TextInputType.text,
|
||||
scrollPhysics: BouncingScrollPhysics(),
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z0-9_ ]')),
|
||||
FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z0-9_-]')),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -4290,7 +4278,6 @@ class CreateNewPlansState extends State<CreateNewPlan> {
|
||||
selectedIstravelUser = isTraveller;
|
||||
});
|
||||
print("USer entered : $otherUserName $userId $isTraveller");
|
||||
getSelectedPlanFor();
|
||||
|
||||
if (isTraveller) {
|
||||
await apiService.handleTripWiseToken(
|
||||
@ -4303,7 +4290,7 @@ class CreateNewPlansState extends State<CreateNewPlan> {
|
||||
context,
|
||||
); // fallback to selfId
|
||||
}
|
||||
|
||||
getSelectedPlanFor();
|
||||
fetchUsrDtlFromSelectedTripUser();
|
||||
|
||||
dynamicItineraryKey.currentState?.loadOrgSelectedAlServices();
|
||||
@ -4311,7 +4298,7 @@ class CreateNewPlansState extends State<CreateNewPlan> {
|
||||
},
|
||||
onClose: () async {
|
||||
print("Choosede Clsoes");
|
||||
await apiService.handleTripWiseToken(selfId!, context);
|
||||
// await apiService.handleTripWiseToken(selfId!, context);
|
||||
fetchUserDetails();
|
||||
},
|
||||
layoutColorForUser: widget.layoutColor!,
|
||||
|
||||
@ -1345,6 +1345,8 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
|
||||
print("📨 Response: ${response.body}");
|
||||
|
||||
await apiService.handleTokenRefresh(context, userId!);
|
||||
|
||||
if (roleId == "4") {
|
||||
context.go('/listPlan');
|
||||
} else {
|
||||
|
||||
@ -2080,7 +2080,7 @@ class TravellerDetailsState extends State<TravellerDetails> {
|
||||
void pickFileWeb() {
|
||||
html.FileUploadInputElement uploadInput = html.FileUploadInputElement();
|
||||
// Accept PDFs and common image formats
|
||||
uploadInput.accept = '.pdf,.jpg,.jpeg,.png,.gif';
|
||||
uploadInput.accept = '.pdf,.jpg,.jpeg,.png';
|
||||
uploadInput.click();
|
||||
|
||||
uploadInput.onChange.listen((e) {
|
||||
@ -2140,6 +2140,18 @@ class TravellerDetailsState extends State<TravellerDetails> {
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 5),
|
||||
Center(
|
||||
child: Text(
|
||||
" * Allow types pdf, jpg, jpeg, png and max size 3MB ",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
if (passportFile != null || passportFileUrlFromApi != null)
|
||||
// Centers the text
|
||||
|
||||
@ -33,6 +33,8 @@ class ApiService {
|
||||
|
||||
if (userData != null) {
|
||||
final pref = await SharedPreferences.getInstance();
|
||||
// await pref.clear();
|
||||
// print("Clearing Token--");
|
||||
await pref.setString('auth_token', token);
|
||||
await pref.setString('user_data', jsonEncode(userData));
|
||||
|
||||
@ -94,6 +96,7 @@ class ApiService {
|
||||
final parts = token.split('.');
|
||||
if (parts.length != 3) throw Exception('Invalid token format');
|
||||
|
||||
print('storeTripUserDetails - $token');
|
||||
final payload = json.decode(
|
||||
utf8.decode(base64Url.decode(base64Url.normalize(parts[1]))),
|
||||
);
|
||||
@ -119,7 +122,7 @@ class ApiService {
|
||||
// print("userData12 - $userRole");
|
||||
}
|
||||
|
||||
await getOrganizationData(context);
|
||||
// await getOrganizationData(context);
|
||||
} catch (e) {
|
||||
print('Error decoding token: $e');
|
||||
}
|
||||
@ -695,7 +698,7 @@ class ApiService {
|
||||
final String apiUrldata = '$apiUrl/api/organizations/find/$orgId';
|
||||
|
||||
final token = await getToken();
|
||||
|
||||
print('ORGFindToken - $token');
|
||||
if (token == null) {
|
||||
throw Exception('Token not found. Please log in.');
|
||||
}
|
||||
@ -850,6 +853,8 @@ class ApiService {
|
||||
|
||||
final token = await getToken();
|
||||
|
||||
print('handleTripWiseToken OLd - $token');
|
||||
|
||||
final response = await http.get(
|
||||
Uri.parse(apiUrldata),
|
||||
headers: {
|
||||
@ -866,7 +871,7 @@ class ApiService {
|
||||
final token = data['token']; // Assuming the token is in response
|
||||
// final userId = data['user_id'].toString();
|
||||
|
||||
print("Token - $token");
|
||||
print('handleTripWiseToken NEW - $token');
|
||||
await storeTripUserDetails(context, token);
|
||||
} else if (response.statusCode == 403) {
|
||||
print("403-FORB");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user