创建用户前邮箱验证
Email verification before user creation
根据document,可以在触发 user().onCreate 时验证电子邮件。据我了解,您只能在创建帐户后发送电子邮件验证 link。怎么可能?
// On sign up.
exports.processSignUp = functions.auth.user().onCreate(async (user) => {
// Check if user meets role criteria.
if (
user.email &&
user.email.endsWith('@admin.example.com') &&
user.emailVerified // Is this can be true at this moment!?
) {
// Grant access
} catch (error) {
console.log(error);
}
}
});
用户配置文件的初始声明由为该用户创建初始 ID 令牌的提供商确定。因此,任何提供商都可以根据需要设置 emailVerified
声明。
built-in 提供者的例子:
- 当您 sign the user in through an email link 时,它隐含地验证了他们可以访问电子邮件地址,因此
emailVerified
设置为 true
。
- 某些提供商已经知道用户拥有某个电子邮件地址,例如 Google 用于
@gmail.com
和 Facebook 用于 @facebook.com
地址,并且可以将 emailVerified
设置为true
自动获取此类地址。
根据document,可以在触发 user().onCreate 时验证电子邮件。据我了解,您只能在创建帐户后发送电子邮件验证 link。怎么可能?
// On sign up.
exports.processSignUp = functions.auth.user().onCreate(async (user) => {
// Check if user meets role criteria.
if (
user.email &&
user.email.endsWith('@admin.example.com') &&
user.emailVerified // Is this can be true at this moment!?
) {
// Grant access
} catch (error) {
console.log(error);
}
}
});
用户配置文件的初始声明由为该用户创建初始 ID 令牌的提供商确定。因此,任何提供商都可以根据需要设置 emailVerified
声明。
built-in 提供者的例子:
- 当您 sign the user in through an email link 时,它隐含地验证了他们可以访问电子邮件地址,因此
emailVerified
设置为true
。 - 某些提供商已经知道用户拥有某个电子邮件地址,例如 Google 用于
@gmail.com
和 Facebook 用于@facebook.com
地址,并且可以将emailVerified
设置为true
自动获取此类地址。