login method
Signs in a user with their Apple account.
If no user exists yet linked to the Apple-provided identifier, a new one
will be created (without any Scopes). Further their provided name and
email (if any) will be used for the UserProfile which will be linked to
their AuthUser.
Returns a session for the user upon successful login.
Implementation
Future<AuthSuccess> login(
final Session session, {
required final String identityToken,
required final String authorizationCode,
/// Whether the sign-in was triggered from a native Apple platform app.
///
/// Pass `false` for web sign-ins or 3rd party platforms like Android.
required final bool isNativeApplePlatformSignIn,
final String? firstName,
final String? lastName,
final Transaction? transaction,
}) async {
return await DatabaseUtil.runInTransactionOrSavepoint(
session.db,
transaction,
(final transaction) async {
final account = await utils.authenticate(
session,
identityToken: identityToken,
authorizationCode: authorizationCode,
isNativeApplePlatformSignIn: isNativeApplePlatformSignIn,
firstName: firstName,
lastName: lastName,
transaction: transaction,
);
if (account.newAccount) {
await _userProfiles.createUserProfile(
session,
account.authUserId,
UserProfileData(
fullName: [account.details.firstName, account.details.lastName]
.nonNulls
.map((final n) => n.trim())
.where((final n) => n.isNotEmpty)
.join(' '),
email: account.details.isVerifiedEmail == true
? account.details.email
: null,
),
transaction: transaction,
);
}
return _tokenIssuer.issueToken(
session,
authUserId: account.authUserId,
method: method,
transaction: transaction,
scopes: account.scopes,
);
},
);
}