From 3061712f657ebe15e19b5de424dd492bcb167a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Sat, 25 Jan 2020 02:00:47 +0100 Subject: [PATCH] feat(auth0-js): correct dbconnection signup details (#41847) - property name (`userMetadata`) - missing props - props documentation - typed signup callback results options https://git.io/Jvqte Thanks! --- types/auth0-js/auth0-js-tests.ts | 35 ++++++++++++++++++++++++++++++-- types/auth0-js/index.d.ts | 21 ++++++++++++++----- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/types/auth0-js/auth0-js-tests.ts b/types/auth0-js/auth0-js-tests.ts index a81ba9f2cc..8f70c426ea 100644 --- a/types/auth0-js/auth0-js-tests.ts +++ b/types/auth0-js/auth0-js-tests.ts @@ -150,7 +150,7 @@ webAuth.signupAndAuthorize({ password: '123456', scope: 'openid', username: "blabla", - user_metadata: { + userMetadata: { foo: 'bar' } }, (err, data) => {}); @@ -263,9 +263,40 @@ authentication.getUserCountry((err, data) => {}); authentication.getSSOData(); authentication.getSSOData(true, (err, data) => {}); +// $ExpectError +authentication.dbConnection.signup(); +// $ExpectError +authentication.dbConnection.signup({}); +// $ExpectError +authentication.dbConnection.signup({ connection: 'bla', email: 'blabla' }); +// $ExpectError +authentication.dbConnection.signup({ connection: 'bla', email: 'blabla', password: '123456' }); authentication.dbConnection.signup( { connection: 'bla', email: 'blabla', password: '123456', username: 'blabla' }, - () => {} + (auth0Error, results) => { + if (auth0Error) { + const { error, errorDescription } = auth0Error; + } + if (results) { + const { email, emailVerified } = results; + } + }, +); +authentication.dbConnection.signup( + { + email: 'the email', + password: 'the password', + connection: 'the_connection', + userMetadata: { + firstName: 'Toon', + lastName: 'De Coninck', + last_location: 'Mexico', + }, + }, + (err, data) => { + console.assert(err === null); + console.assert(data.email !== null); + }, ); authentication.dbConnection.changePassword({connection: 'bla', email: 'blabla'}, () => {}); diff --git a/types/auth0-js/index.d.ts b/types/auth0-js/index.d.ts index 8255ebc82e..f29a9e4de1 100644 --- a/types/auth0-js/index.d.ts +++ b/types/auth0-js/index.d.ts @@ -113,11 +113,10 @@ export class DBConnection { constructor(request: any, option: any); /** - * Signup a new user - * - * @param options: https://auth0.com/docs/api/authentication#!#post--dbconnections-signup + * Creates a new user in a Auth0 Database connection + * @param options https://auth0.com/docs/api/authentication#signup */ - signup(options: DbSignUpOptions, callback: Auth0Callback): void; + signup(options: DbSignUpOptions, callback: Auth0Callback): void; /** * Initializes the change password flow @@ -834,13 +833,25 @@ export interface DelegationOptions { } export interface DbSignUpOptions { + /** user email address */ email: string; + /** user password */ password: string; + /** name of the connection where the user will be created */ connection: string; /** User desired username. Required if you use a database connection and you have enabled `Requires Username` */ username?: string; scope?: string; - user_metadata?: any; + /** additional signup attributes used for creating the user. Will be stored in `user_metadata` */ + userMetadata?: any; +} + +/** result of the signup request */ +export interface DbSignUpResults { + /** user's email */ + email: string; + /** if the user's email was verified */ + emailVerified: boolean; } export interface ParseHashOptions {