Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async setUserData(user) {
- const userToken = user.getIdToken().then((token) => {
- return token;
- });
- const userData = new User(user.uid, user.email, user.displayName, user.photoURL, userToken);
- if (this.platform.is('capacitor')) Plugins.Storage.set({ key: 'authData', value: JSON.stringify(userData) });
- }
- // Handle login with redirect for web Google auth
- private async handleRedirect() {
- if (await this.isRedirect()) {
- return null;
- }
- const loading = await this.loadingController.create();
- await loading.present();
- const result = await this.afAuth.getRedirectResult();
- if (result.user) {
- await this.setUserData(result);
- }
- await loading.dismiss();
- await this.setRedirect(false);
- return result;
- }
- autoLogin() {
- return from(Plugins.Storage.get({ key: 'authData' })).pipe(
- map((storedData) => {
- if (!storedData || !storedData.value) return null;
- const parsedData = JSON.parse(storedData.value) as User;
- const user = new User(
- parsedData.uid,
- parsedData.email,
- parsedData.token,
- parsedData.photoURL,
- parsedData.token
- );
- return user;
- }),
- tap((user) => {
- if (user) this.user$.next(user);
- }),
- map((user) => {
- return !!user;
- })
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement