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