auth_interceptor.dart 599 B

12345678910111213141516171819202122
  1. import 'dart:async';
  2. import 'package:flustars/flustars.dart';
  3. import 'package:get/get_connect/http/src/request/request.dart';
  4. import 'package:ftrecruiter/comm/constants/sp_constant.dart';
  5. import 'package:ftrecruiter/comm/utils/device_utils.dart';
  6. //自动添加Token,自动刷新Token
  7. FutureOr<Request> authInterceptor(Request request) async {
  8. final token = SpUtil.getString(SPConstant.SP_KEY_TOKEN);
  9. if (!TextUtil.isEmpty(token)) {
  10. request.headers['Authorization'] = 'bearer$token';
  11. }
  12. if (!Device.isWeb) {
  13. request.headers['User-Agent'] = 'Mozilla/5.0';
  14. }
  15. return request;
  16. }