linkAndRetrieveDataWithTicket method
匿名账号数据迁移到正式账号
Implementation
Future<CloudBaseAuthState> linkAndRetrieveDataWithTicket(
String ticket) async {
String? uuid = await cache.getStore(cache.anonymousUuidKey);
String? refreshToken = await cache.getStore(cache.refreshTokenKey);
final CloudBaseResponse? res = await CloudBaseRequest(super.core)
.postWithoutAuth('auth.linkAndRetrieveDataWithTicket', {
'anonymous_uuid': uuid,
'refresh_token': refreshToken,
'ticket': ticket
});
if (res == null) {
throw new CloudBaseException(
code: CloudBaseExceptionCode.NULL_RESPONES,
message: "unknown error, res is null");
}
if (res.code != null) {
throw new CloudBaseException(code: res.code, message: res.message);
}
if (res.data != null && res.data['refresh_token'] != null) {
/// 转正后清除本地保存的匿名uuid
await _clearAnonymousUUID();
String newRefreshToken = res.data['refresh_token'];
await setRefreshToken(newRefreshToken);
await refreshAccessToken();
return CloudBaseAuthState(refreshToken: newRefreshToken);
} else {
throw CloudBaseException(
code: CloudBaseExceptionCode.AUTH_FAILED, message: '匿名转化失败');
}
}