@@ -37,6 +37,7 @@ import { verifySignedAuthResponse } from "./internal/verifySignedAuthResponse";
3737 * ```ts
3838 * app.use("/auth", createSeamlessAuthServer({
3939 * authServerUrl: "https://identifier.seamlessauth.com",
40+ * cookieDomain: "mycompany.com",
4041 * accesscookieName: "sa_access",
4142 * registrationCookieName: "sa_registration",
4243 * refreshCookieName: "sa_refresh",
@@ -45,6 +46,7 @@ import { verifySignedAuthResponse } from "./internal/verifySignedAuthResponse";
4546 *
4647 * @param opts - Configuration options for the Seamless Auth proxy:
4748 * - `authServerUrl` — Base URL of your Seamless Auth instance (required)
49+ * - `cookieDomain` — Domain attribute applied to all auth cookies
4850 * - `accesscookieName` — Name of the session access cookie
4951 * - `registrationCookieName` — Name of the ephemeral registration cookie
5052 * - `refreshCookieName` — Name of the refresh token cookie
@@ -61,14 +63,18 @@ export function createSeamlessAuthServer(
6163
6264 const {
6365 authServerUrl,
66+ cookieDomain = "" ,
6467 accesscookieName = "seamless-access" ,
6568 registrationCookieName = "seamless-ephemeral" ,
6669 refreshCookieName = "seamless-refresh" ,
6770 preAuthCookieName = "seamless-ephemeral" ,
6871 } = opts ;
6972
7073 const proxy =
71- ( path : string , method : "GET" | "POST" | "PUT" | "DELETE" = "POST" ) =>
74+ (
75+ path : string ,
76+ method : "GET" | "POST" | "PUT" | "PATCH" | "DELETE" = "POST"
77+ ) =>
7278 async ( req : Request , res : Response ) => {
7379 try {
7480 const response = await authFetch ( req , `${ authServerUrl } /${ path } ` , {
@@ -84,6 +90,7 @@ export function createSeamlessAuthServer(
8490 r . use (
8591 createEnsureCookiesMiddleware ( {
8692 authServerUrl,
93+ cookieDomain,
8794 accesscookieName,
8895 registrationCookieName,
8996 refreshCookieName,
@@ -99,6 +106,8 @@ export function createSeamlessAuthServer(
99106 r . post ( "/otp/verify-email-otp" , proxy ( "otp/verify-email-otp" ) ) ;
100107 r . post ( "/login" , login ) ;
101108 r . post ( "/users/update" , proxy ( "users/update" ) ) ;
109+ r . post ( "/users/credentials" , proxy ( "users/credentials" ) ) ;
110+ r . delete ( "/users/credentials" , proxy ( "users/credentials" ) ) ;
102111 r . post ( "/registration/register" , register ) ;
103112 r . get ( "/users/me" , me ) ;
104113 r . get ( "/logout" , logout ) ;
@@ -123,7 +132,13 @@ export function createSeamlessAuthServer(
123132 throw new Error ( "Signature mismatch with data payload" ) ;
124133 }
125134
126- setSessionCookie ( res , { sub : data . sub } , data . ttl , preAuthCookieName ) ;
135+ setSessionCookie (
136+ res ,
137+ { sub : data . sub } ,
138+ cookieDomain ,
139+ data . ttl ,
140+ preAuthCookieName
141+ ) ;
127142 res . status ( 204 ) . end ( ) ;
128143 }
129144
@@ -135,7 +150,13 @@ export function createSeamlessAuthServer(
135150 const data = ( await up . json ( ) ) as any ;
136151 if ( ! up . ok ) return res . status ( up . status ) . json ( data ) ;
137152
138- setSessionCookie ( res , { sub : data . sub } , data . ttl , registrationCookieName ) ;
153+ setSessionCookie (
154+ res ,
155+ { sub : data . sub } ,
156+ cookieDomain ,
157+ data . ttl ,
158+ registrationCookieName
159+ ) ;
139160 res . status ( 200 ) . json ( data ) . end ( ) ;
140161 }
141162
@@ -163,13 +184,15 @@ export function createSeamlessAuthServer(
163184 setSessionCookie (
164185 res ,
165186 { sub : data . sub , roles : data . roles } ,
187+ cookieDomain ,
166188 data . ttl ,
167189 accesscookieName
168190 ) ;
169191
170192 setSessionCookie (
171193 res ,
172194 { sub : data . sub , refreshToken : data . refreshToken } ,
195+ cookieDomain ,
173196 data . refreshTtl ,
174197 refreshCookieName
175198 ) ;
@@ -192,6 +215,7 @@ export function createSeamlessAuthServer(
192215 setSessionCookie (
193216 res ,
194217 { sub : data . sub , roles : data . roles } ,
218+ cookieDomain ,
195219 data . ttl ,
196220 accesscookieName
197221 ) ;
@@ -205,6 +229,7 @@ export function createSeamlessAuthServer(
205229
206230 clearAllCookies (
207231 res ,
232+ cookieDomain ,
208233 accesscookieName ,
209234 registrationCookieName ,
210235 refreshCookieName
@@ -218,8 +243,8 @@ export function createSeamlessAuthServer(
218243 } ) ;
219244 const data = ( await up . json ( ) ) as any ;
220245
221- clearSessionCookie ( res , preAuthCookieName ) ;
246+ clearSessionCookie ( res , cookieDomain , preAuthCookieName ) ;
222247 if ( ! data . user ) return res . status ( 401 ) . json ( { error : "unauthenticated" } ) ;
223- res . json ( { user : data . user } ) ;
248+ res . json ( { user : data . user , credentials : data . credentials } ) ;
224249 }
225250}
0 commit comments