I have a login form built with Ionic 3. When I upload it on Firebase as a PWA, I wish users to be able to save their passwords and sign in using saved passwords but autosaved passwords work neither on Safari nor on Chrome although I turned autocomplete=on in ion-input fields.
Below is my HTML code:
<ion-content>
<div style="margin-top: 20px; margin-bottom: 20px">
<ion-grid>
<ion-row align-items-center>
<ion-col align-self-center>
<div class="centering">
<img class="iconSmall" src="assets/imgs/iconSmall.png">
<p class="title">Log into your account</p>
</div>
<form [formGroup]="user" (ngSubmit)="loginUser(user)">
<ion-list>
<ion-item>
<ion-label floating>Email</ion-label>
<ion-input type="text" formControlName="email" autocomplete="on"></ion-input>
</ion-item>
<ion-item *ngIf="!user.controls.email.valid && user.controls.email.dirty" no-lines>
<p>Please enter a valid email address.</p>
</ion-item>
<ion-item>
<ion-label floating>Password</ion-label>
<ion-input type="password" formControlName="password" autocomplete="on"></ion-input>
</ion-item>
<ion-item *ngIf="!user.controls.password.valid && user.controls.password.dirty" no-lines>
<p>Password must have at least 6 characters.</p>
</ion-item>
</ion-list>
<div style="text-align: center;">
<button ion-button type="submit" [disabled]="user.invalid" color="primary" style="width: 90%; font-weight: bold;">log in</button>
</div>
</form>
<div class="forgotButton" (click)="goToResetPassword()">
<p>Forgot your password?</p>
</div>
</ion-col>
</ion-row>
</ion-grid>
</div>
</ion-content>
And on the .ts file of the form I use the following relevant code:
import { Component } from '@angular/core';
import { IonicPage, NavController, Loading, LoadingController, Alert, AlertController } from 'ionic-angular';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { EmailValidator } from './../../validators/email';
@IonicPage()
@Component({
selector: 'page-member-login',
templateUrl: 'member-login.html',
})
export class MemberLoginPage {
user : FormGroup; //define the variable to contain form group
public loading: Loading;
constructor(public navCtrl: NavController,
private fb: FormBuilder,
public loadingCtrl:LoadingController,
public alertCtrl: AlertController,
public authProvider:AuthProvider) {
this.user = this.fb.group ({
email: ['', EmailValidator.isValid],
password: ['', [Validators.minLength(6), Validators.required]],
})
};
loginUser(): void {
// login code goes here
};
goToResetPassword():void{
this.navCtrl.push('ResetPasswordPage');
};
}
export interface User {
email: string;
password: string;
}
What can I change in the code to make sure autosaved passwords appear and are usable when users come in the second time? Here is the complete error:
- The browser asks if I want to save password. I say “yes”.
- Next time I sign in, the username and password appears in the bar on the keyboard.
- When I click on the username, it doesn’t fill in the form fields.
This is for PWA. I use:
ionic build – --prod
And upload the www files to firebase using
firebase deploy