@redzone/taunt-logins 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +8 -17
- package/dist/cjs/index.d.cts +1 -2
- package/dist/es/index.d.ts +1 -2
- package/dist/es/index.js +8 -17
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -354,12 +354,6 @@ class TauntApi {
|
|
|
354
354
|
Accept: "application/json",
|
|
355
355
|
...headers
|
|
356
356
|
};
|
|
357
|
-
if (this.accessToken) {
|
|
358
|
-
headers = {
|
|
359
|
-
...headers,
|
|
360
|
-
Authorization: `Bearer ${this.accessToken}`
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
357
|
const response = await this._axios.request({
|
|
364
358
|
url,
|
|
365
359
|
method,
|
|
@@ -371,9 +365,6 @@ class TauntApi {
|
|
|
371
365
|
if (data?.refreshToken) {
|
|
372
366
|
this.refreshToken = data.refreshToken;
|
|
373
367
|
}
|
|
374
|
-
if (data?.accessToken) {
|
|
375
|
-
this.accessToken = data.accessToken;
|
|
376
|
-
}
|
|
377
368
|
return data;
|
|
378
369
|
}
|
|
379
370
|
async post(url, body = {}, headers = {}) {
|
|
@@ -387,8 +378,7 @@ class TauntApi {
|
|
|
387
378
|
if (!walletAddress) {
|
|
388
379
|
throw new Error("No wallet address found");
|
|
389
380
|
}
|
|
390
|
-
const
|
|
391
|
-
const clientNonce = crypto.getRandomValues(cryptoValuesArray).toString();
|
|
381
|
+
const clientNonce = this.randomTokenString();
|
|
392
382
|
const serverNonce = await this.nonceLogin(walletAddress, clientNonce);
|
|
393
383
|
const payload = JSON.stringify({
|
|
394
384
|
clientNonce,
|
|
@@ -520,7 +510,6 @@ class TauntApi {
|
|
|
520
510
|
}
|
|
521
511
|
constructor(endpoint){
|
|
522
512
|
this.refreshToken = null;
|
|
523
|
-
this.accessToken = null;
|
|
524
513
|
this.claimrToken = null;
|
|
525
514
|
this.onError = async (error)=>{
|
|
526
515
|
const originalRequest = error.config;
|
|
@@ -540,18 +529,16 @@ class TauntApi {
|
|
|
540
529
|
return Promise.reject(ErrorFromResponse(error.response));
|
|
541
530
|
};
|
|
542
531
|
this.setLoginDetails = async (props, checkGet = true)=>{
|
|
543
|
-
this.accessToken = props.accessToken;
|
|
544
532
|
this.refreshToken = props.refreshToken;
|
|
545
533
|
if (checkGet) {
|
|
546
534
|
const user = await this.getLoggedInUser();
|
|
547
535
|
if (!user) {
|
|
548
|
-
this.accessToken = null;
|
|
549
536
|
this.refreshToken = null;
|
|
550
537
|
return null;
|
|
551
538
|
}
|
|
552
539
|
}
|
|
553
540
|
return {
|
|
554
|
-
accessToken:
|
|
541
|
+
accessToken: props.accessToken,
|
|
555
542
|
refreshToken: this.refreshToken
|
|
556
543
|
};
|
|
557
544
|
};
|
|
@@ -593,12 +580,16 @@ class TauntApi {
|
|
|
593
580
|
const data = await this.get("v1/claimr/referral-code");
|
|
594
581
|
return data.data?.ref_id;
|
|
595
582
|
};
|
|
596
|
-
this.randomTokenString = ()=>
|
|
583
|
+
this.randomTokenString = (len = 3)=>{
|
|
584
|
+
const cryptoValuesArray = new Uint32Array(len);
|
|
585
|
+
return crypto.getRandomValues(cryptoValuesArray).toString();
|
|
586
|
+
};
|
|
597
587
|
// Use the cookie stored in the browser to get the user and save user model in state and local storage
|
|
598
588
|
// This assumes that the user is logged to backend in and has a cookie jwt
|
|
599
589
|
this.getLoggedInUser = ()=>this.get("/v1/auth/me");
|
|
600
590
|
this._axios = axios__default.default.create({
|
|
601
|
-
baseURL: endpoint
|
|
591
|
+
baseURL: endpoint,
|
|
592
|
+
withCredentials: true
|
|
602
593
|
});
|
|
603
594
|
// Response interceptor for API calls
|
|
604
595
|
this._axios.interceptors.response.use((response)=>response, (error)=>this.onError(error));
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -251,7 +251,6 @@ interface AxiosErrorResponse {
|
|
|
251
251
|
declare class TauntApi {
|
|
252
252
|
private _axios;
|
|
253
253
|
private refreshToken;
|
|
254
|
-
private accessToken;
|
|
255
254
|
private claimrToken;
|
|
256
255
|
constructor(endpoint: string);
|
|
257
256
|
onError: (error: AxiosErrorResponse) => Promise<AxiosResponse<any, any, {}>>;
|
|
@@ -270,7 +269,7 @@ declare class TauntApi {
|
|
|
270
269
|
getClaimrToken: () => Promise<string>;
|
|
271
270
|
getClaimrSkulls: () => Promise<ClaimrCampaignData>;
|
|
272
271
|
getClaimrReferralCode: () => Promise<string | undefined>;
|
|
273
|
-
randomTokenString: () => string;
|
|
272
|
+
randomTokenString: (len?: number) => string;
|
|
274
273
|
withProvider(provider: {
|
|
275
274
|
getAddress: () => Promise<string | undefined | null>;
|
|
276
275
|
personalSign: (message: string, address: string) => Promise<string | undefined | null>;
|
package/dist/es/index.d.ts
CHANGED
|
@@ -251,7 +251,6 @@ interface AxiosErrorResponse {
|
|
|
251
251
|
declare class TauntApi {
|
|
252
252
|
private _axios;
|
|
253
253
|
private refreshToken;
|
|
254
|
-
private accessToken;
|
|
255
254
|
private claimrToken;
|
|
256
255
|
constructor(endpoint: string);
|
|
257
256
|
onError: (error: AxiosErrorResponse) => Promise<AxiosResponse<any, any, {}>>;
|
|
@@ -270,7 +269,7 @@ declare class TauntApi {
|
|
|
270
269
|
getClaimrToken: () => Promise<string>;
|
|
271
270
|
getClaimrSkulls: () => Promise<ClaimrCampaignData>;
|
|
272
271
|
getClaimrReferralCode: () => Promise<string | undefined>;
|
|
273
|
-
randomTokenString: () => string;
|
|
272
|
+
randomTokenString: (len?: number) => string;
|
|
274
273
|
withProvider(provider: {
|
|
275
274
|
getAddress: () => Promise<string | undefined | null>;
|
|
276
275
|
personalSign: (message: string, address: string) => Promise<string | undefined | null>;
|
package/dist/es/index.js
CHANGED
|
@@ -348,12 +348,6 @@ class TauntApi {
|
|
|
348
348
|
Accept: "application/json",
|
|
349
349
|
...headers
|
|
350
350
|
};
|
|
351
|
-
if (this.accessToken) {
|
|
352
|
-
headers = {
|
|
353
|
-
...headers,
|
|
354
|
-
Authorization: `Bearer ${this.accessToken}`
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
351
|
const response = await this._axios.request({
|
|
358
352
|
url,
|
|
359
353
|
method,
|
|
@@ -365,9 +359,6 @@ class TauntApi {
|
|
|
365
359
|
if (data?.refreshToken) {
|
|
366
360
|
this.refreshToken = data.refreshToken;
|
|
367
361
|
}
|
|
368
|
-
if (data?.accessToken) {
|
|
369
|
-
this.accessToken = data.accessToken;
|
|
370
|
-
}
|
|
371
362
|
return data;
|
|
372
363
|
}
|
|
373
364
|
async post(url, body = {}, headers = {}) {
|
|
@@ -381,8 +372,7 @@ class TauntApi {
|
|
|
381
372
|
if (!walletAddress) {
|
|
382
373
|
throw new Error("No wallet address found");
|
|
383
374
|
}
|
|
384
|
-
const
|
|
385
|
-
const clientNonce = crypto.getRandomValues(cryptoValuesArray).toString();
|
|
375
|
+
const clientNonce = this.randomTokenString();
|
|
386
376
|
const serverNonce = await this.nonceLogin(walletAddress, clientNonce);
|
|
387
377
|
const payload = JSON.stringify({
|
|
388
378
|
clientNonce,
|
|
@@ -514,7 +504,6 @@ class TauntApi {
|
|
|
514
504
|
}
|
|
515
505
|
constructor(endpoint){
|
|
516
506
|
this.refreshToken = null;
|
|
517
|
-
this.accessToken = null;
|
|
518
507
|
this.claimrToken = null;
|
|
519
508
|
this.onError = async (error)=>{
|
|
520
509
|
const originalRequest = error.config;
|
|
@@ -534,18 +523,16 @@ class TauntApi {
|
|
|
534
523
|
return Promise.reject(ErrorFromResponse(error.response));
|
|
535
524
|
};
|
|
536
525
|
this.setLoginDetails = async (props, checkGet = true)=>{
|
|
537
|
-
this.accessToken = props.accessToken;
|
|
538
526
|
this.refreshToken = props.refreshToken;
|
|
539
527
|
if (checkGet) {
|
|
540
528
|
const user = await this.getLoggedInUser();
|
|
541
529
|
if (!user) {
|
|
542
|
-
this.accessToken = null;
|
|
543
530
|
this.refreshToken = null;
|
|
544
531
|
return null;
|
|
545
532
|
}
|
|
546
533
|
}
|
|
547
534
|
return {
|
|
548
|
-
accessToken:
|
|
535
|
+
accessToken: props.accessToken,
|
|
549
536
|
refreshToken: this.refreshToken
|
|
550
537
|
};
|
|
551
538
|
};
|
|
@@ -587,12 +574,16 @@ class TauntApi {
|
|
|
587
574
|
const data = await this.get("v1/claimr/referral-code");
|
|
588
575
|
return data.data?.ref_id;
|
|
589
576
|
};
|
|
590
|
-
this.randomTokenString = ()=>
|
|
577
|
+
this.randomTokenString = (len = 3)=>{
|
|
578
|
+
const cryptoValuesArray = new Uint32Array(len);
|
|
579
|
+
return crypto.getRandomValues(cryptoValuesArray).toString();
|
|
580
|
+
};
|
|
591
581
|
// Use the cookie stored in the browser to get the user and save user model in state and local storage
|
|
592
582
|
// This assumes that the user is logged to backend in and has a cookie jwt
|
|
593
583
|
this.getLoggedInUser = ()=>this.get("/v1/auth/me");
|
|
594
584
|
this._axios = axios.create({
|
|
595
|
-
baseURL: endpoint
|
|
585
|
+
baseURL: endpoint,
|
|
586
|
+
withCredentials: true
|
|
596
587
|
});
|
|
597
588
|
// Response interceptor for API calls
|
|
598
589
|
this._axios.interceptors.response.use((response)=>response, (error)=>this.onError(error));
|