@@ -3,113 +3,113 @@ import { getThirdwebBaseUrl } from "../../../../../utils/domains.js";
33import { stringify } from "../../../../../utils/json.js" ;
44import { getLoginCallbackUrl } from "../../../core/authentication/getLoginPath.js" ;
55import type {
6- AuthStoredTokenWithCookieReturnType ,
7- MultiStepAuthArgsType ,
8- PreAuthArgsType ,
6+ AuthStoredTokenWithCookieReturnType ,
7+ MultiStepAuthArgsType ,
8+ PreAuthArgsType ,
99} from "../../../core/authentication/types.js" ;
1010import type { Ecosystem } from "../../../core/wallet/types.js" ;
1111
1212/**
1313 * @internal
1414 */
1515export const sendOtp = async ( args : PreAuthArgsType ) : Promise < void > => {
16- const { client, ecosystem } = args ;
17- const url = `${ getThirdwebBaseUrl ( "api" ) } /v1/auth/initiate` ;
18-
19- const headers : Record < string , string > = {
20- "Content-Type" : "application/json" ,
21- "x-client-id" : client . clientId ,
22- } ;
23-
24- if ( ecosystem ?. id ) {
25- headers [ "x-ecosystem-id" ] = ecosystem . id ;
26- }
27-
28- if ( ecosystem ?. partnerId ) {
29- headers [ "x-ecosystem-partner-id" ] = ecosystem . partnerId ;
30- }
31-
32- const body = ( ( ) => {
33- switch ( args . strategy ) {
34- case "email" :
35- return {
36- type : "email" ,
37- email : args . email ,
38- } ;
39- case "phone" :
40- return {
41- type : "phone" ,
42- phone : args . phoneNumber ,
43- } ;
44- }
45- } ) ( ) ;
46-
47- const response = await fetch ( url , {
48- body : stringify ( body ) ,
49- headers,
50- method : "POST" ,
51- } ) ;
52-
53- if ( ! response . ok ) {
54- throw new Error ( "Failed to send verification code" ) ;
55- }
56-
57- return await response . json ( ) ;
16+ const { client, ecosystem } = args ;
17+ const url = `${ getThirdwebBaseUrl ( "api" ) } /v1/auth/initiate` ;
18+
19+ const headers : Record < string , string > = {
20+ "Content-Type" : "application/json" ,
21+ "x-client-id" : client . clientId ,
22+ } ;
23+
24+ if ( ecosystem ?. id ) {
25+ headers [ "x-ecosystem-id" ] = ecosystem . id ;
26+ }
27+
28+ if ( ecosystem ?. partnerId ) {
29+ headers [ "x-ecosystem-partner-id" ] = ecosystem . partnerId ;
30+ }
31+
32+ const body = ( ( ) => {
33+ switch ( args . strategy ) {
34+ case "email" :
35+ return {
36+ type : "email" ,
37+ email : args . email ,
38+ } ;
39+ case "phone" :
40+ return {
41+ type : "phone" ,
42+ phone : args . phoneNumber ,
43+ } ;
44+ }
45+ } ) ( ) ;
46+
47+ const response = await fetch ( url , {
48+ body : stringify ( body ) ,
49+ headers,
50+ method : "POST" ,
51+ } ) ;
52+
53+ if ( ! response . ok ) {
54+ throw new Error ( "Failed to send verification code" ) ;
55+ }
56+
57+ return await response . json ( ) ;
5858} ;
5959
6060/**
6161 * @internal
6262 */
6363export const verifyOtp = async (
64- args : MultiStepAuthArgsType & {
65- client : ThirdwebClient ;
66- ecosystem ?: Ecosystem ;
67- } ,
64+ args : MultiStepAuthArgsType & {
65+ client : ThirdwebClient ;
66+ ecosystem ?: Ecosystem ;
67+ } ,
6868) : Promise < AuthStoredTokenWithCookieReturnType > => {
69- const { client, ecosystem } = args ;
70- const url = getLoginCallbackUrl ( {
71- authOption : args . strategy ,
72- client : args . client ,
73- ecosystem : args . ecosystem ,
74- } ) ;
75-
76- const headers : Record < string , string > = {
77- "Content-Type" : "application/json" ,
78- "x-client-id" : client . clientId ,
79- } ;
80-
81- if ( ecosystem ?. id ) {
82- headers [ "x-ecosystem-id" ] = ecosystem . id ;
83- }
84-
85- if ( ecosystem ?. partnerId ) {
86- headers [ "x-ecosystem-partner-id" ] = ecosystem . partnerId ;
87- }
88-
89- const body = ( ( ) => {
90- switch ( args . strategy ) {
91- case "email" :
92- return {
93- code : args . verificationCode ,
94- email : args . email ,
95- } ;
96- case "phone" :
97- return {
98- code : args . verificationCode ,
99- phone : args . phoneNumber ,
100- } ;
101- }
102- } ) ( ) ;
103-
104- const response = await fetch ( url , {
105- body : stringify ( body ) ,
106- headers,
107- method : "POST" ,
108- } ) ;
109-
110- if ( ! response . ok ) {
111- throw new Error ( "Failed to verify verification code" ) ;
112- }
113-
114- return await response . json ( ) ;
69+ const { client, ecosystem } = args ;
70+ const url = getLoginCallbackUrl ( {
71+ authOption : args . strategy ,
72+ client : args . client ,
73+ ecosystem : args . ecosystem ,
74+ } ) ;
75+
76+ const headers : Record < string , string > = {
77+ "Content-Type" : "application/json" ,
78+ "x-client-id" : client . clientId ,
79+ } ;
80+
81+ if ( ecosystem ?. id ) {
82+ headers [ "x-ecosystem-id" ] = ecosystem . id ;
83+ }
84+
85+ if ( ecosystem ?. partnerId ) {
86+ headers [ "x-ecosystem-partner-id" ] = ecosystem . partnerId ;
87+ }
88+
89+ const body = ( ( ) => {
90+ switch ( args . strategy ) {
91+ case "email" :
92+ return {
93+ code : args . verificationCode ,
94+ email : args . email ,
95+ } ;
96+ case "phone" :
97+ return {
98+ code : args . verificationCode ,
99+ phone : args . phoneNumber ,
100+ } ;
101+ }
102+ } ) ( ) ;
103+
104+ const response = await fetch ( url , {
105+ body : stringify ( body ) ,
106+ headers,
107+ method : "POST" ,
108+ } ) ;
109+
110+ if ( ! response . ok ) {
111+ throw new Error ( "Failed to verify verification code" ) ;
112+ }
113+
114+ return await response . json ( ) ;
115115} ;
0 commit comments