Skip to content

Instantly share code, notes, and snippets.

@nbnD
Created December 5, 2022 10:58
Show Gist options
  • Save nbnD/13bbeaf86a2279c5aaab35ffa8126043 to your computer and use it in GitHub Desktop.
Save nbnD/13bbeaf86a2279c5aaab35ffa8126043 to your computer and use it in GitHub Desktop.
import 'package:http/http.dart' as http;
Future<String> getIdToken({bool? force}) async {
// fetch update token
return "abc*******";
}
Future<void> main() async {
final client = http.Client();
final token = await getIdToken();
final response = getRequest(client, token);
if (response.statusCode == 401) {
getRequest(client, token);
} else {
///other process
}
}
getRequest(client, token) async {
await client.get(Uri.parse("https://senkyaku.jp"),
headers: {"Authorisation": "Bearer $token"});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment