11import qs from 'qs' ;
22import {
33 AuthenticateData ,
4+ AuthenticateDataV2 ,
45 SignUpData ,
6+ SignUpDataV2 ,
57 RequestNewPasswordData ,
68 SetNewPasswordData ,
79 UpdateAccountData ,
@@ -116,6 +118,51 @@ class Account extends BaseExtend {
116118 return respData ;
117119 }
118120
121+ /**
122+ * Signs in the user v2
123+ * @method signInV2
124+ * @async
125+ * @typedef {Object } AxiosResponse<CreateAccount>
126+ * @param {AuthenticateDataV2 } data - Contains {
127+ * email: string,
128+ * password: string,
129+ * clientId: string,
130+ * referrer: string,
131+ * }
132+ * @example
133+ * InPlayer.Account.signInV2({
134+ * email: 'test@test .com',
135+ * password: 'test123',
136+ * clientId: '123-123-hf1hd1-12dhd1',
137+ * referrer: 'http://localhost:3000/',
138+ * })
139+ * .then(data => console.log(data));
140+ * @returns {AxiosResponse<CreateAccount> }
141+ */
142+ async signInV2 ( data : AuthenticateDataV2 ) {
143+ const body = {
144+ client_id : data . clientId ,
145+ grant_type : 'password' ,
146+ referrer : data . referrer ,
147+ username : data . email ,
148+ password : data . password ,
149+ } ;
150+
151+ const respData = await this . request . post ( API . signInV2 , qs . stringify ( body ) , {
152+ headers : {
153+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
154+ } ,
155+ } ) ;
156+
157+ await this . request . setToken (
158+ respData . data . access_token ,
159+ respData . data . refresh_token ,
160+ respData . data . expires ,
161+ ) ;
162+
163+ return respData ;
164+ }
165+
119166 /**
120167 * Signs up/Registers user
121168 * @method signUp
@@ -129,8 +176,7 @@ class Account extends BaseExtend {
129176 * type: string,
130177 * referrer: string,
131178 * brandingId?: number,
132- * metadata?: { [key: string]: string }\
133- * dateOfBirth?: string,
179+ * metadata?: { [key: string]: string }
134180 * }
135181 * @example
136182 * InPlayer.Account.signUp({
@@ -174,6 +220,63 @@ class Account extends BaseExtend {
174220 return resp ;
175221 }
176222
223+ /**
224+ * Signs up/Registers user v2
225+ * @method signUpV2
226+ * @async
227+ * @param {SignUpDataV2 } data - Contains {
228+ * fullName: string,
229+ * email: string
230+ * password: string,
231+ * passwordConfirmation: string,
232+ * clientId: string,
233+ * type: string,
234+ * referrer: string,
235+ * brandingId?: number,
236+ * metadata?: { [key: string]: string }
237+ * }
238+ * @example
239+ * InPlayer.Account.signUpV2({
240+ * fullName: "test",
241+ * email: "test32@test .com",
242+ * password: "12345678",
243+ * passwordConfirmation: "12345678",
244+ * clientId: "528b1b80-5868-4abc-a9b6-4d3455d719c8",
245+ * type: "consumer",
246+ * referrer: "http://localhost:3000/",
247+ * brandingId?: 12345,
248+ * metadata : { country: "Macedonia" },
249+ * })
250+ * .then(data => console.log(data));
251+ * @returns {AxiosResponse<CreateAccount> }
252+ */
253+ async signUpV2 ( data : SignUpDataV2 ) {
254+ const body = {
255+ full_name : data . fullName ,
256+ username : data . email ,
257+ password : data . password ,
258+ password_confirmation : data . passwordConfirmation ,
259+ client_id : data . clientId ,
260+ type : data . type ,
261+ referrer : data . referrer ,
262+ grant_type : 'password' ,
263+ metadata : data . metadata ,
264+ branding_id : data . brandingId ,
265+ } ;
266+
267+ const resp = await this . request . post ( API . signUpV2 , qs . stringify ( body ) , {
268+ headers : { 'Content-Type' : 'application/x-www-form-urlencoded' } ,
269+ } ) ;
270+
271+ await this . request . setToken (
272+ resp . data . access_token ,
273+ resp . data . refresh_token ,
274+ resp . data . expires ,
275+ ) ;
276+
277+ return resp ;
278+ }
279+
177280 /**
178281 * Signs out the user and destroys cookies
179282 * @method signOut
0 commit comments