File tree Expand file tree Collapse file tree 6 files changed +49
-8
lines changed
Expand file tree Collapse file tree 6 files changed +49
-8
lines changed Original file line number Diff line number Diff line change @@ -6,3 +6,12 @@ export interface CreatePasswordlessSessionOptions {
66 connection ?: string ;
77 expiresIn ?: number ;
88}
9+
10+ export interface SerializedCreatePasswordlessSessionOptions {
11+ type : 'MagicLink' ;
12+ email : string ;
13+ redirect_uri ?: string ;
14+ state ?: string ;
15+ connection ?: string ;
16+ expires_in ?: number ;
17+ }
Original file line number Diff line number Diff line change 1- export { PasswordlessSession } from './passwordless-session.interface' ;
2- export { CreatePasswordlessSessionOptions } from './create-passwordless-session-options.interface' ;
3- export { SendSessionResponse } from './send-session-response.interface' ;
1+ export * from './passwordless-session.interface' ;
2+ export * from './create-passwordless-session-options.interface' ;
3+ export * from './send-session-response.interface' ;
Original file line number Diff line number Diff line change 11export interface PasswordlessSession {
2+ id : string ;
3+ email : string ;
4+ expiresAt : Date ;
5+ link : string ;
6+ object : 'passwordless_session' ;
7+ }
8+
9+ export interface PasswordlessSessionResponse {
210 id : string ;
311 email : string ;
412 expires_at : Date ;
Original file line number Diff line number Diff line change 11import { WorkOS } from '../workos' ;
2- import { PasswordlessSession } from './interfaces/passwordless-session.interface' ;
3- import { CreatePasswordlessSessionOptions } from './interfaces/create-passwordless-session-options.interface' ;
4- import { SendSessionResponse } from './interfaces/send-session-response.interface' ;
2+ import {
3+ CreatePasswordlessSessionOptions ,
4+ PasswordlessSession ,
5+ PasswordlessSessionResponse ,
6+ SendSessionResponse ,
7+ SerializedCreatePasswordlessSessionOptions ,
8+ } from './interfaces' ;
9+ import { deserializePasswordlessSession } from './serializers/passwordless-session.serializer' ;
510
611export class Passwordless {
712 constructor ( private readonly workos : WorkOS ) { }
@@ -11,12 +16,17 @@ export class Passwordless {
1116 expiresIn,
1217 ...options
1318 } : CreatePasswordlessSessionOptions ) : Promise < PasswordlessSession > {
14- const { data } = await this . workos . post ( '/passwordless/sessions' , {
19+ const { data } = await this . workos . post <
20+ PasswordlessSessionResponse ,
21+ any ,
22+ SerializedCreatePasswordlessSessionOptions
23+ > ( '/passwordless/sessions' , {
1524 ...options ,
1625 redirect_uri : redirectURI ,
1726 expires_in : expiresIn ,
1827 } ) ;
19- return data ;
28+
29+ return deserializePasswordlessSession ( data ) ;
2030 }
2131
2232 async sendSession ( sessionId : string ) : Promise < SendSessionResponse > {
Original file line number Diff line number Diff line change 1+ import {
2+ PasswordlessSession ,
3+ PasswordlessSessionResponse ,
4+ } from '../interfaces' ;
5+
6+ export const deserializePasswordlessSession = (
7+ passwordlessSession : PasswordlessSessionResponse ,
8+ ) : PasswordlessSession => ( {
9+ id : passwordlessSession . id ,
10+ email : passwordlessSession . email ,
11+ expiresAt : passwordlessSession . expires_at ,
12+ link : passwordlessSession . link ,
13+ object : passwordlessSession . object ,
14+ } ) ;
You can’t perform that action at this time.
0 commit comments