I'm attempting to integrate Firebase Authentication into my Angular application.
Here's the signUp()
function within my AuthService
:
signUp(email: string, password: string, name: string) {
const userCredential = from(
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(
(data) => {
let newUser: firebase.User = data.user;
newUser.updateProfile({
displayName: name,
photoURL: ''
}).then(() => {
firebase.firestore().collection('users').add({
userId: firebase.auth().currentUser.uid,
userName: firebase.auth().currentUser.displayName,
created: firebase.firestore.FieldValue.serverTimestamp()
});
});
Plugins.Storage.set({
key: 'userCredential',
value: newUser.uid
});
}
)
);
return userCredential;
}
Using this function, I'm able to save newUser.uid
in local storage via Capacitor's Storage
plugin.
However, I'm looking to store the same details as shown below (specifically localId
, email
, idToken
, and expirationTime
):
login(email: string, password: string) {
return this.http.post<AuthResponseData>(
`firebaseUrl/v1/accounts:signInWithPassword?key=${
environment.firebaseAPIKey
}`,
{ email: email, password: password, returnSecureToken: true }
).pipe(tap(this.setUserData.bind(this)));
}
private setUserData(userData: AuthResponseData) {
const expirationTime = new Date(
new Date().getTime() + (+userData.expiresIn * 1000)
);
this._user.next(
new User(
userData.localId,
userData.email,
userData.idToken,
expirationTime
)
);
this.storeAuthData(userData.localId, userData.idToken, expirationTime.toISOString(), userData.email);
}
private storeAuthData(userId: string, token: string, tokenExpirationDate: string, email: string) {
const data = JSON.stringify({
userId: userId,
token: token,
tokenExpirationDate: tokenExpirationDate,
email: email
});
Plugins.Storage.set({ key: 'authData', value: data });
}
Could someone guide me on how to obtain these 4 values in my signUp()
function?