The official snippet here says:
// You can access the new user via result.user
// Additional user info profile not available via:
// result.additionalUserInfo.profile == null
// You can check if the user is new or existing:
// result.additionalUserInfo.isNewUser
Even the API reference says :
Object that contains additional user information as a result of a successful sign-in, link, or re-authentication operation.
However I get additionalUserInfo is undefined
. I need to detect if the email link login is a new user or not.
My code:
await setPersistence(auth, browserLocalPersistence);
const result = await signInWithEmailLink(auth, email.value, window.location.href);
if (result && result.user) {
window.localStorage.removeItem('email');
window.localStorage.removeItem('its');
console.log(result.additionalUserInfo.isNewUser()); // undefined
return router.push({ path: "/dashboard" });
}
The official snippet here says:
// You can access the new user via result.user
// Additional user info profile not available via:
// result.additionalUserInfo.profile == null
// You can check if the user is new or existing:
// result.additionalUserInfo.isNewUser
Even the API reference says :
Object that contains additional user information as a result of a successful sign-in, link, or re-authentication operation.
However I get additionalUserInfo is undefined
. I need to detect if the email link login is a new user or not.
My code:
await setPersistence(auth, browserLocalPersistence);
const result = await signInWithEmailLink(auth, email.value, window.location.href);
if (result && result.user) {
window.localStorage.removeItem('email');
window.localStorage.removeItem('its');
console.log(result.additionalUserInfo.isNewUser()); // undefined
return router.push({ path: "/dashboard" });
}
Share
Improve this question
edited Aug 15, 2021 at 12:15
Dharmaraj
51k8 gold badges67 silver badges98 bronze badges
asked Aug 15, 2021 at 11:17
eozzyeozzy
68.9k109 gold badges285 silver badges447 bronze badges
3
-
Can you share your code where
additionalUserInfo
undefined? – Dharmaraj Commented Aug 15, 2021 at 11:20 - @Dharmaraj Sure, done. – eozzy Commented Aug 15, 2021 at 11:32
-
Tried both, its the
additionalUserInfo
thats undefined – eozzy Commented Aug 15, 2021 at 11:33
1 Answer
Reset to default 11You need to use the getAdditionalUserInfo
method separately in the new modular SDK as mentioned in this Github issue.
import {signInWithEmailLink, getAdditionalUserInfo} from "firebase/auth"
const result = await signInWithEmailLink(auth, email.value, window.location.href);
const {isNewUser} = getAdditionalUserInfo(result)
// Pass the UserCredential ^^^^^^
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744309357a4567874.html
评论列表(0条)