@@ -95,20 +95,28 @@ async function createLocalServerSession(signal: AbortSignal) {
9595
9696 if ( signal . aborted ) throw new Error ( "Sign in aborted" ) ;
9797
98- return paramsValidator . parse ( {
99- type : url . searchParams . get ( "type" ) ,
100- api_key : url . searchParams . get ( "api_key" ) ,
101- user_id : url . searchParams . get ( "user_id" ) ,
102- } ) ;
98+ const a = [ ...url . searchParams ] . reduce ( ( acc , [ k , v ] ) => {
99+ acc [ k ] = v ;
100+ return acc ;
101+ } , { } as any ) ;
102+
103+ return paramsValidator . parse ( a ) ;
103104 } ,
104105 } ;
105106}
106107
107- const paramsValidator = z . object ( {
108- type : z . literal ( "api_key" ) ,
109- api_key : z . string ( ) ,
110- user_id : z . string ( ) ,
111- } ) ;
108+ const paramsValidator = z . union ( [
109+ z . object ( {
110+ type : z . literal ( "api_key" ) ,
111+ api_key : z . string ( ) ,
112+ user_id : z . string ( ) ,
113+ } ) ,
114+ z . object ( {
115+ token : z . string ( ) ,
116+ user_id : z . string ( ) ,
117+ expires : z . coerce . number ( ) ,
118+ } ) ,
119+ ] ) ;
112120
113121async function createDeepLinkSession ( signal : AbortSignal ) {
114122 let res : ( data : z . infer < typeof paramsValidator > ) => void ;
@@ -122,11 +130,12 @@ async function createDeepLinkSession(signal: AbortSignal) {
122130 const url = new URL ( urlString ) ;
123131
124132 res (
125- paramsValidator . parse ( {
126- type : url . searchParams . get ( "type" ) ,
127- api_key : url . searchParams . get ( "api_key" ) ,
128- user_id : url . searchParams . get ( "user_id" ) ,
129- } )
133+ paramsValidator . parse (
134+ [ ...url . searchParams ] . reduce ( ( acc , [ k , v ] ) => {
135+ acc [ k ] = v ;
136+ return acc ;
137+ } , { } as any )
138+ )
130139 ) ;
131140 }
132141 } ) ;
@@ -147,7 +156,10 @@ async function processAuthData(data: z.infer<typeof paramsValidator>) {
147156
148157 const existingAuth = await authStore . get ( ) ;
149158 await authStore . set ( {
150- secret : { api_key : data . api_key } ,
159+ secret :
160+ "api_key" in data
161+ ? { api_key : data . api_key }
162+ : { token : data . token , expires : data . expires } ,
151163 user_id : data . user_id ,
152164 intercom_hash : existingAuth ?. intercom_hash ?? "" ,
153165 plan : null ,
0 commit comments