Auto Filling Credentials
Android, iOS and the Web have built in password managers that will automatically detect username and password fields and securely store and recall these credentials.
In order for Apple and Google to autofill and save credentials, a two-way association between your website and app must be configured. In the guide we'll follow the same steps used for Deep Linking but we'll add steps for Capacitor Configuration and use of the autocomplete
attribute.
Code Your App
Your application will need an ion-input
for the username and password which must use the attribute autocomplete
. An example is shown below:
- Angular
- Javascript
<form>
<ion-list>
<ion-item>
<ion-label>E-Mail Address</ion-label>
<ion-input appAutofill type="email" name="email" autocomplete="email" [(ngModel)]="email" required email></ion-input>
</ion-item>
<ion-item>
<ion-label>Password</ion-label>
<ion-input appAutofill type="password" name="password" autocomplete="current-password" required [(ngModel)]="password"></ion-input>
</ion-item>
</ion-list>
<ion-button type="submit">Submit</ion-button>
</form>
Due to a webkit bug related to ion-input
with automatic filling of fields you will need a workaround by copying this this directive into your code.
This sample application uses the techniques in this guide to allow auto filling of credentials on iOS, Android and the Web.
<form>
<ion-list>
<ion-item>
<ion-label>E-Mail Address</ion-label>
<ion-input type="email" name="email" autocomplete="email" required email></ion-input>
</ion-item>
<ion-item>
<ion-label>Password</ion-label>
<ion-input id="pwd" type="password" name="password" autocomplete="current-password" required></ion-input>
</ion-item>
</ion-list>
<ion-button type="submit">Submit</ion-button>
</form>
Due to a webkit bug related to ion-input
with automatic filling of fields you will need this workaround code:
document.getElementById('pwd').children[0].addEventListener('change', (e) => {
this.password = (e.target as any).value;
});
The autocomplete
attribute allows auto filling of credential types like username
, current-pasword
, new-password
. It can also be used without this additional configuration for phone numbers, one time codes, credit card information and more.
Set Capacitor Server Hostname
By default Capacitor will serve using the domain localhost
(capacitor://localhost
on iOS and http://localhost
on Android). As you will want the password manager to suggest the stored credentials for your app you will need to change the configuration from localhost
to my-app.com
(the domain you associated to your app).
You can do this in your capacitor.config.ts
or capacitor.config.json
file:
const config: CapacitorConfig = {
...
server: {
hostname: 'my-app.com',
androidScheme: 'https',
}
};
Configuration for iOS
Configuration in XCode
Open your project in XCode and navigate to Signing & Capabilities
.
- Click the
+
and add the capability ofAssociated Domains
. - In the Domains section click the
+
and provide an entryapplinks:my-app.com
wheremy-app.com
is the domain name you own and will create an App Association File for. - Make sure
Automatically manage signing
is enabled (otherwise you will need to configure App Ids, Capabilities and Profiles in the Apple Developer Portal).
Apple App Site Association File
Create the site association file called apple-app-site-association
similar to the one below replacing TEAMID.BUNDLEID
with your own Apple Team ID and App Bundle ID (example: 8L65AZE66A.com.company.myapp
).
{
"applinks": {
"details": [
{
"appID": "TEAMID.BUNDLEID",
"paths": ["*"]
}
]
}
}