Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i use the PasswordCredential API from Chrome in Angular 7

i m making an App with Angular 7 and i want to store the password of the users in the chrome built in a link! and i cant use it because cant create the " new PasswordCredential ".

i can check if it is availbe using '(window as any).PasswordCredential', but i cant create the instance of PasswordCredential

         if ((window as any).PasswordCredential) {
              const credentials = new PasswordCredential ({
                name: userLogin.username,
                password: userLogin.password,
              });
              return navigator.credentials.store(credentials);
            }

the error shows 'Cannot find name 'PasswordCredential'.ts(2304)'

and in the navigator also show 'Property 'credentials' does not exist on type 'Navigator'.ts(2339)'

like image 962
Sandy Veliz Avatar asked Oct 31 '25 10:10

Sandy Veliz


1 Answers

First you need to write:

    declare global {
     interface Window {
      PasswordCredential: any;
      FederatedCredential: any;
     }
    }

Then:

if (window.PasswordCredential) {
      ...your code here
    }
like image 74
MargeKh Avatar answered Nov 02 '25 01:11

MargeKh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!