diff --git a/types/netlify-identity-widget/index.d.ts b/types/netlify-identity-widget/index.d.ts index de113b2342..4e963e6cc9 100644 --- a/types/netlify-identity-widget/index.d.ts +++ b/types/netlify-identity-widget/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for netlify-identity-widget 1.4 +// Type definitions for netlify-identity-widget 1.9 // Project: https://github.com/netlify/netlify-identity-widget, https://identity.netlify.com // Definitions by: Naveen Kumar Sangi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -14,6 +14,12 @@ export interface InitOptions { // identity endpoint is served.This is common for Cordova or Electron // apps where you host from localhost or a file. APIUrl?: string; + + // Enable Netlify logo + logo?: boolean; + + // Initial language + locale?: string; } export interface Token { @@ -41,6 +47,8 @@ export interface User { confirmed_at: string; created_at: string; updated_at: string; + invited_at: string; + recovery_sent_at: string; email: string; id: string; role: string; @@ -80,8 +88,22 @@ export function on(event: 'login', cb: (user: User) => void): void; export function on(event: 'logout' | 'open' | 'close', cb: () => void): void; export function on(event: 'error', cb: (err: Error) => void): void; +/** + * Unregisters callbacks to corresponding events on the widget. + * Set the callback argument to remove only the specified one. + */ +export function off(event: 'init', cb?: (user: User | null) => void): void; +export function off(event: 'login', cb?: (user: User) => void): void; +export function off(event: 'logout' | 'open' | 'close', cb?: () => void): void; +export function off(event: 'error', cb?: (err: Error) => void): void; + /** * Logs out the current user. Returns a Promise when a user is * logged in, else returns undefined. */ export function logout(): Promise | undefined; + +/** + * Set current language + */ +export function setLocale(locale: string): void; diff --git a/types/netlify-identity-widget/netlify-identity-widget-tests.ts b/types/netlify-identity-widget/netlify-identity-widget-tests.ts index f44daaec37..9067bfd4da 100644 --- a/types/netlify-identity-widget/netlify-identity-widget-tests.ts +++ b/types/netlify-identity-widget/netlify-identity-widget-tests.ts @@ -15,10 +15,18 @@ NetlifyIdentityWidget.init({ container: 'body' }); // Type 3: Initialize with a specific APIUrl NetlifyIdentityWidget.init({ APIUrl: 'https://www.example.com/.netlify/functions/identity' }); -// Type 4: Initialize with both the options specified +// Type 4: Initialize with a logo option +NetlifyIdentityWidget.init({ logo: true }); + +// Type 5: Initialize with a specific locale +NetlifyIdentityWidget.init({ locale: 'en' }); + +// Type 6: Initialize with all specified options NetlifyIdentityWidget.init({ APIUrl: 'https://www.example.com/.netlify/functions/identity', container: 'body', + logo: true, + locale: 'en', }); // Open widget modal to let users login @@ -26,6 +34,8 @@ NetlifyIdentityWidget.open(); NetlifyIdentityWidget.on('open', () => { // Widget is open and ready to login }); +NetlifyIdentityWidget.off('open'); +NetlifyIdentityWidget.off('open', () => {}); // Open wigdet modal with signup tab selected NetlifyIdentityWidget.open('signup'); @@ -35,27 +45,37 @@ NetlifyIdentityWidget.close(); NetlifyIdentityWidget.on('close', () => { // Widget is closed }); +NetlifyIdentityWidget.off('close'); +NetlifyIdentityWidget.off('close', () => {}); // Event handling after login NetlifyIdentityWidget.on('login', (user) => { // You can now use User info after a successful login }); +NetlifyIdentityWidget.off('login'); +NetlifyIdentityWidget.off('login', (user) => {}); // Event handling after logout NetlifyIdentityWidget.on('logout', () => { // You can now notify that the logout was successful }); +NetlifyIdentityWidget.off('logout'); +NetlifyIdentityWidget.off('logout', () => {}); // Event handling after login on page refresh NetlifyIdentityWidget.on('init', (user) => { // Now the widget is ready to use // If a user was already logged in, the value is returned else null is passed via callback }); +NetlifyIdentityWidget.off('init'); +NetlifyIdentityWidget.off('init', (user) => {}); // Event handling on errors NetlifyIdentityWidget.on('error', (err) => { // The error occured during operation is passed in via callback }); +NetlifyIdentityWidget.off('error'); +NetlifyIdentityWidget.off('error', (err) => {}); // Use the current logged in user const user = NetlifyIdentityWidget.currentUser();