我正在尝试使用REST API来注册用户。到目前为止,我无需注册即可注册用户。但是,我需要通过发送确认电子邮件来验证用户的电子邮件,然后在确认后注册用户。我该怎么办?
这是我当前的代码:
class Auth with ChangeNotifier {
String _token;
DateTime _expiryDate;
String _userId;
Timer _authTimer;
String get token {
if (_expiryDate != null &&
_expiryDate.isAfter(DateTime.now()) &&
_token != null) {
return _token;
}
}
bool get isAuth {
return token != null;
}
String get userId{
return _userId;
}
Future<void> _authenticate(
String email, String password, String urlSegment) async {
final url =
'`https://www.googleapis.com/identitytoolkit/v3/relyingparty`/$urlSegment?key={MyAPIKEY}';
try {
final response = await http.post(
url,
body: json.encode(
{
'email': email,
'password': password,
'returnSecureToken': true,
},
),
);
final responseData = json.decode(response.body);
if (responseData['error'] != null) {
throw HttpException(responseData['error']['message']);
}
_token = responseData['idToken'];
_userId = responseData['localId'];
_expiryDate = DateTime.now()
.add(Duration(seconds: int.parse(responseData['expiresIn'])));
notifyListeners();
} catch (error) {
throw error;
}
}
Future<void> signup(String email, String password) async {
return _authenticate(email, password, 'signupNewUser');
}
}