@niledatabase/server 4.0.0-alpha.2 → 4.0.0-alpha.21

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/index.d.ts CHANGED
@@ -28,6 +28,7 @@ type ApiParams = {
28
28
  routes?: Partial<Routes>;
29
29
  routePrefix?: string | undefined;
30
30
  secureCookies?: boolean;
31
+ origin?: null | undefined | string;
31
32
  };
32
33
  declare class ApiConfig {
33
34
  cookieKey?: string;
@@ -35,6 +36,7 @@ declare class ApiConfig {
35
36
  routes?: Partial<Routes>;
36
37
  routePrefix?: string;
37
38
  secureCookies?: boolean;
39
+ origin?: string | null;
38
40
  /**
39
41
  * The client side callback url. Defaults to nothing (so nile.origin will be it), but in the cases of x-origin, you want to set this explicitly to be sure nile-auth does the right thing
40
42
  * If this is set, any `callbackUrl` from the client will be ignored.
@@ -72,10 +74,10 @@ type NilePoolConfig = PoolConfig & {
72
74
  afterCreate?: AfterCreate;
73
75
  };
74
76
  type LoggerType = {
75
- info?: (args: unknown[]) => void;
76
- warn?: (args: unknown[]) => void;
77
- error?: (args: unknown[]) => void;
78
- debug?: (args: unknown[]) => void;
77
+ info?: (args: unknown | unknown[]) => void;
78
+ warn?: (args: unknown | unknown[]) => void;
79
+ error?: (args: unknown | unknown[]) => void;
80
+ debug?: (args: unknown | unknown[]) => void;
79
81
  };
80
82
  type ServerConfig = {
81
83
  databaseId?: string;
@@ -145,6 +147,13 @@ type Tenant = {
145
147
  name: string;
146
148
  };
147
149
 
150
+ type Provider = {
151
+ id: string;
152
+ name: string;
153
+ type: string;
154
+ signinUrl: string;
155
+ callbackUr: string;
156
+ };
148
157
  type JWT = {
149
158
  email: string;
150
159
  sub: string;
@@ -208,10 +217,25 @@ type NileRequest<T> = NRequest<T> | T;
208
217
 
209
218
  declare class Auth extends Config {
210
219
  headers?: Headers;
211
- constructor(config: Config, headers?: Headers);
220
+ resetHeaders?: (headers?: Headers) => void;
221
+ constructor(config: Config, headers?: Headers, params?: {
222
+ resetHeaders: () => void;
223
+ });
212
224
  handleHeaders(init?: RequestInit): RequestInit | undefined;
213
225
  get sessionUrl(): string;
214
- getSession: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<JWT | ActiveSession | Response | undefined>;
226
+ getSession: <T = JWT | ActiveSession | Response | undefined>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
227
+ get getCsrfUrl(): string;
228
+ getCsrf<T = Response | JSON>(req: NileRequest<void> | Headers, init?: RequestInit, raw?: boolean): Promise<T>;
229
+ get listProvidersUrl(): string;
230
+ listProviders: <T = Response | {
231
+ [key: string]: Provider;
232
+ }>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
233
+ get signOutUrl(): string;
234
+ signOut: <T = Response | {
235
+ url: string;
236
+ }>(req: NileRequest<void | {
237
+ callbackUrl?: string;
238
+ }> | Headers, init?: RequestInit) => Promise<T>;
215
239
  }
216
240
 
217
241
  declare class Tenants extends Config {
@@ -220,18 +244,18 @@ declare class Tenants extends Config {
220
244
  handleHeaders(init?: RequestInit): RequestInit | undefined;
221
245
  get tenantsUrl(): string;
222
246
  get tenantUrl(): string;
223
- createTenant: (req: NileRequest<{
247
+ createTenant: <T = Tenant | Response>(req: NileRequest<{
224
248
  name: string;
225
- }> | Headers | string, init?: RequestInit) => Promise<Tenant | Response>;
226
- getTenant: (req: NileRequest<{
249
+ }> | Headers | string, init?: RequestInit) => Promise<T>;
250
+ getTenant: <T = Tenant | Response>(req: NileRequest<{
227
251
  id: string;
228
- }> | Headers | string | void, init?: RequestInit) => Promise<Tenant | Response>;
252
+ }> | Headers | string | void, init?: RequestInit) => Promise<T>;
229
253
  get tenantListUrl(): string;
230
- listTenants: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<Tenant[] | Response>;
231
- deleteTenant: (req: NileRequest<void> | Headers | string, init?: RequestInit) => Promise<Response>;
232
- updateTenant: (req: NileRequest<void> | Headers | {
254
+ listTenants: <T = Tenant[] | Response>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
255
+ deleteTenant: <T = Response>(req: NileRequest<void> | Headers | string, init?: RequestInit) => Promise<T>;
256
+ updateTenant: <T = Tenant | Response>(req: NileRequest<void> | Headers | {
233
257
  name: string;
234
- }, init?: RequestInit) => Promise<Tenant | Response>;
258
+ }, init?: RequestInit) => Promise<T>;
235
259
  }
236
260
 
237
261
  declare class Users extends Config {
@@ -242,21 +266,21 @@ declare class Users extends Config {
242
266
  get linkUsersUrl(): string;
243
267
  get tenantUserUrl(): string;
244
268
  handleHeaders(init?: RequestInit): RequestInit | undefined;
245
- createUser: (req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => Promise<User | Response>;
246
- createTenantUser: (req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => Promise<User | Response>;
247
- updateUser: (req: NileRequest<Partial<Omit<User, "email" | "tenants" | "created" | "updated">>>, init?: RequestInit) => Promise<User | Response>;
248
- listUsers: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<User[] | Response>;
249
- linkUser: (req: NileRequest<{
269
+ createUser: <T = User | Response>(req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => Promise<T>;
270
+ createTenantUser: <T = User | Response>(req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => Promise<T>;
271
+ updateUser: <T = User[] | Response>(req: NileRequest<Partial<Omit<User, "email" | "tenants" | "created" | "updated">>>, init?: RequestInit) => Promise<T>;
272
+ listUsers: <T = User[] | Response>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
273
+ linkUser: <T = User | Response>(req: NileRequest<{
250
274
  id: string;
251
275
  tenantId?: string;
252
- }> | Headers | string, init?: RequestInit) => Promise<User | Response>;
253
- unlinkUser: (req: NileRequest<{
276
+ }> | Headers | string, init?: RequestInit) => Promise<T>;
277
+ unlinkUser: <T = Response>(req: NileRequest<{
254
278
  id: string;
255
279
  tenantId?: string;
256
- }> | Headers | string, init?: RequestInit) => Promise<Response>;
280
+ }> | Headers | string, init?: RequestInit) => Promise<T>;
257
281
  get meUrl(): string;
258
- me: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<User | Response>;
259
- updateMe: (req: NileRequest<Partial<Omit<User, "email" | "id" | "tenants" | "created" | "updated">>> | Headers, init?: RequestInit) => Promise<User | Response>;
282
+ me: <T = User | Response>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
283
+ updateMe: <T = User | Response>(req: NileRequest<Partial<Omit<User, "email" | "id" | "tenants" | "created" | "updated">>> | Headers, init?: RequestInit) => Promise<T>;
260
284
  }
261
285
 
262
286
  declare class Api {
@@ -279,13 +303,18 @@ declare class Api {
279
303
  put: string[];
280
304
  };
281
305
  constructor(config: Config);
282
- updateConfig(config: Config): void;
306
+ reset: () => void;
307
+ updateConfig: (config: Config) => void;
308
+ resetHeaders: (headers?: Headers) => void;
283
309
  set headers(headers: Headers);
284
- login(payload: {
310
+ get headers(): Headers | undefined;
311
+ login: (payload: {
285
312
  email: string;
286
313
  password: string;
287
- }): Promise<void>;
288
- session(req?: Request | Headers | null | undefined): Promise<Response | JWT | ActiveSession | null | undefined>;
314
+ }, config?: {
315
+ returnResponse?: boolean;
316
+ }) => Promise<Response | undefined>;
317
+ session: (req?: Request | Headers | null | undefined) => Promise<Response | JWT | ActiveSession | null | undefined>;
289
318
  }
290
319
 
291
320
  declare class Server {
package/dist/index.js CHANGED
@@ -79,7 +79,7 @@ var X_NILE_SECURECOOKIES = "nile.secure_cookies";
79
79
 
80
80
  // src/api/utils/request.ts
81
81
  async function request(url, _init, config) {
82
- const { info, error } = Logger(config, "[REQUEST]");
82
+ const { debug, info, error } = Logger(config, "[REQUEST]");
83
83
  const { request: request2, ...init } = _init;
84
84
  const requestUrl = new URL(request2.url);
85
85
  const updatedHeaders = new Headers({});
@@ -97,9 +97,17 @@ async function request(url, _init, config) {
97
97
  }
98
98
  updatedHeaders.set("host", requestUrl.host);
99
99
  if (config.api.callbackUrl) {
100
- updatedHeaders.set(X_NILE_ORIGIN, config.api.callbackUrl);
100
+ const cbUrl = new URL(config.api.callbackUrl);
101
+ debug(
102
+ `Obtained origin from config.api.callbackUrl ${config.api.callbackUrl}`
103
+ );
104
+ updatedHeaders.set(X_NILE_ORIGIN, cbUrl.origin);
105
+ } else if (config.api.origin) {
106
+ debug(`Obtained origin from config.api.origin ${config.api.origin}`);
107
+ updatedHeaders.set(X_NILE_ORIGIN, config.api.origin);
101
108
  } else {
102
109
  updatedHeaders.set(X_NILE_ORIGIN, requestUrl.origin);
110
+ debug(`Obtained origin from request ${requestUrl.origin}`);
103
111
  }
104
112
  const params = { ...init, headers: updatedHeaders };
105
113
  if (params.method === "POST" || params.method === "PUT") {
@@ -426,6 +434,7 @@ var ApiConfig = class {
426
434
  routes;
427
435
  routePrefix;
428
436
  secureCookies;
437
+ origin;
429
438
  /**
430
439
  * The client side callback url. Defaults to nothing (so nile.origin will be it), but in the cases of x-origin, you want to set this explicitly to be sure nile-auth does the right thing
431
440
  * If this is set, any `callbackUrl` from the client will be ignored.
@@ -441,6 +450,7 @@ var ApiConfig = class {
441
450
  this.basePath = getBasePath(envVarConfig);
442
451
  this.routes = config?.api?.routes;
443
452
  this.routePrefix = config?.api?.routePrefix;
453
+ this.origin = config?.api?.origin;
444
454
  }
445
455
  get token() {
446
456
  return this._token;
@@ -1073,12 +1083,9 @@ async function _fetch(config, path, opts) {
1073
1083
  if (response?.status === 405) {
1074
1084
  return new ResponseError("Method not allowed", { status: 405 });
1075
1085
  }
1076
- let res;
1077
1086
  const errorHandler = typeof response?.clone === "function" ? response.clone() : null;
1078
1087
  let msg = "";
1079
- try {
1080
- res = await response?.json();
1081
- } catch (e) {
1088
+ const res = await response?.json().catch(async (e) => {
1082
1089
  if (errorHandler) {
1083
1090
  msg = await errorHandler.text();
1084
1091
  if (msg) {
@@ -1091,7 +1098,8 @@ async function _fetch(config, path, opts) {
1091
1098
  if (!msg) {
1092
1099
  error("[fetch][response]", { e });
1093
1100
  }
1094
- }
1101
+ return e;
1102
+ });
1095
1103
  if (msg) {
1096
1104
  return new ResponseError(msg, { status: errorHandler?.status });
1097
1105
  }
@@ -1110,7 +1118,8 @@ async function _fetch(config, path, opts) {
1110
1118
  error(
1111
1119
  `[fetch][response][status: ${errorHandler?.status}] UNHANDLED ERROR`,
1112
1120
  {
1113
- res
1121
+ response,
1122
+ message: await response.text()
1114
1123
  }
1115
1124
  );
1116
1125
  return new ResponseError(null, {
@@ -1534,11 +1543,7 @@ function matches12(configRoutes, request2) {
1534
1543
  // src/api/routes/auth/password-reset.ts
1535
1544
  var key10 = "PASSWORD_RESET";
1536
1545
  async function route13(req, config) {
1537
- let url = proxyRoutes(config)[key10];
1538
- const { searchParams } = new URL(req.url);
1539
- if (searchParams.size > 0) {
1540
- url = `${url}?${searchParams.toString()}`;
1541
- }
1546
+ const url = proxyRoutes(config)[key10];
1542
1547
  const res = await request(
1543
1548
  url,
1544
1549
  {
@@ -1651,8 +1656,16 @@ function POSTER(configRoutes, config) {
1651
1656
  const { info, warn, error } = Logger(config, "[POST MATCHER]");
1652
1657
  return async function POST5(req) {
1653
1658
  if (matchesLog(configRoutes, req)) {
1654
- error(req.body && await req.json());
1655
- return new Response(null, { status: 200 });
1659
+ if (req.body) {
1660
+ try {
1661
+ const text = await req.text();
1662
+ error(text);
1663
+ return new Response(null, {
1664
+ status: 200
1665
+ });
1666
+ } catch (e) {
1667
+ }
1668
+ }
1656
1669
  }
1657
1670
  if (matches3(configRoutes, req)) {
1658
1671
  info("matches tenant users");
@@ -1777,7 +1790,7 @@ var appRoutes = (prefix = "/api") => ({
1777
1790
  TENANT_USER: `${prefix}/tenants/{tenantId}/users/{userId}`,
1778
1791
  TENANT_USERS: `${prefix}/tenants/{tenantId}/users`,
1779
1792
  SIGNUP: `${prefix}/signup`,
1780
- LOG: `${prefix}/auth/_log`
1793
+ LOG: `${prefix}/_log`
1781
1794
  });
1782
1795
 
1783
1796
  // src/utils/Requester/index.ts
@@ -1787,9 +1800,9 @@ var Requester = class extends Config {
1787
1800
  }
1788
1801
  async rawRequest(method, url, init, body) {
1789
1802
  const _init = {
1790
- ...init,
1791
1803
  body,
1792
- method
1804
+ method,
1805
+ ...init
1793
1806
  };
1794
1807
  const res = await _fetch(this, url, _init);
1795
1808
  if (res instanceof ResponseError) {
@@ -1858,8 +1871,11 @@ var Requester = class extends Config {
1858
1871
  }
1859
1872
  return response;
1860
1873
  }
1861
- async get(req, url, init) {
1874
+ async get(req, url, init, raw = false) {
1862
1875
  const response = await this.request("GET", url, req, init);
1876
+ if (raw) {
1877
+ return response;
1878
+ }
1863
1879
  if (response && response.status >= 200 && response.status < 300) {
1864
1880
  const cloned = response.clone();
1865
1881
  try {
@@ -1887,8 +1903,8 @@ var Requester = class extends Config {
1887
1903
  };
1888
1904
 
1889
1905
  // src/auth/index.ts
1890
- var ORIGIN = "https://us-west-2.api.dev.thenile.dev";
1891
1906
  function serverLogin(config, handlers) {
1907
+ const ORIGIN = config.api.origin ?? "http://localhost:3000";
1892
1908
  const { info, error, debug } = Logger(config, "[server side login]");
1893
1909
  const routes = appRoutes(config.api.routePrefix);
1894
1910
  return async function login({
@@ -1979,17 +1995,31 @@ function serverLogin(config, handlers) {
1979
1995
  ...baseHeaders,
1980
1996
  cookie: [token, csrfCookie].join("; ")
1981
1997
  });
1982
- return headers;
1998
+ return [headers, loginRes];
1983
1999
  };
1984
2000
  }
1985
2001
  var Auth = class extends Config {
1986
2002
  headers;
1987
- constructor(config, headers) {
2003
+ resetHeaders;
2004
+ constructor(config, headers, params) {
1988
2005
  super(config);
2006
+ this.logger = Logger(config, "[auth]");
1989
2007
  this.headers = headers;
2008
+ this.logger = Logger(config, "[auth]");
2009
+ this.resetHeaders = params?.resetHeaders;
1990
2010
  }
1991
2011
  handleHeaders(init) {
1992
2012
  if (this.headers) {
2013
+ const cburl = getCallbackUrl2(this.headers);
2014
+ if (cburl) {
2015
+ try {
2016
+ this.headers.set(X_NILE_ORIGIN, new URL(cburl).origin);
2017
+ } catch (e) {
2018
+ if (this.logger?.debug) {
2019
+ this.logger.debug("Invalid URL supplied by cookie header");
2020
+ }
2021
+ }
2022
+ }
1993
2023
  if (init) {
1994
2024
  init.headers = new Headers({ ...this.headers, ...init?.headers });
1995
2025
  return init;
@@ -2014,6 +2044,113 @@ var Auth = class extends Config {
2014
2044
  }
2015
2045
  return session;
2016
2046
  };
2047
+ get getCsrfUrl() {
2048
+ return "/auth/csrf";
2049
+ }
2050
+ async getCsrf(req, init, raw = false) {
2051
+ const _requester = new Requester(this);
2052
+ const _init = this.handleHeaders(init);
2053
+ return await _requester.get(req, this.getCsrfUrl, _init, raw);
2054
+ }
2055
+ get listProvidersUrl() {
2056
+ return "/auth/providers";
2057
+ }
2058
+ listProviders = async (req, init) => {
2059
+ const _requester = new Requester(this);
2060
+ const _init = this.handleHeaders(init);
2061
+ return await _requester.get(req, this.listProvidersUrl, _init);
2062
+ };
2063
+ get signOutUrl() {
2064
+ return "/auth/signout";
2065
+ }
2066
+ signOut = async (req, init) => {
2067
+ const _requester = new Requester(this);
2068
+ const _init = this.handleHeaders(init);
2069
+ const csrf = await this.getCsrf(
2070
+ req,
2071
+ void 0,
2072
+ true
2073
+ );
2074
+ const csrfHeader = getCsrfToken(csrf.headers, this.headers);
2075
+ const callbackUrl = req && "callbackUrl" in req ? String(req.callbackUrl) : "/";
2076
+ if (!csrfHeader) {
2077
+ this.logger?.debug && this.logger.debug("Request blocked from invalid csrf header");
2078
+ return new Response("Request blocked", { status: 400 });
2079
+ }
2080
+ const headers = new Headers(_init?.headers);
2081
+ const { csrfToken } = await csrf.json() ?? {};
2082
+ const cooks = getCookies(headers);
2083
+ if (csrfHeader) {
2084
+ if (cooks["__Secure-nile.csrf-token"]) {
2085
+ cooks["__Secure-nile.csrf-token"] = encodeURIComponent(csrfHeader);
2086
+ }
2087
+ if (cooks["nile.csrf-token"]) {
2088
+ cooks["nile.csrf-token"] = encodeURIComponent(csrfHeader);
2089
+ }
2090
+ }
2091
+ headers.set(
2092
+ "cookie",
2093
+ Object.keys(cooks).map((key12) => `${key12}=${cooks[key12]}`).join("; ")
2094
+ );
2095
+ const res = await _requester.post(req, this.signOutUrl, {
2096
+ method: "post",
2097
+ body: JSON.stringify({
2098
+ csrfToken,
2099
+ callbackUrl,
2100
+ json: String(true)
2101
+ }),
2102
+ ..._init,
2103
+ headers
2104
+ });
2105
+ this.resetHeaders && this.resetHeaders();
2106
+ return res;
2107
+ };
2108
+ };
2109
+ function getCallbackUrl2(headers) {
2110
+ if (headers) {
2111
+ const cookies = getCookies(headers);
2112
+ if (cookies) {
2113
+ return cookies["__Secure-nile.callback-url"] || cookies["nile.callback-url"];
2114
+ }
2115
+ }
2116
+ }
2117
+ function getCsrfToken(headers, initHeaders) {
2118
+ if (headers) {
2119
+ const cookies = getCookies(headers);
2120
+ let validCookie = "";
2121
+ if (cookies) {
2122
+ validCookie = cookies["__Secure-nile.csrf-token"] || cookies["nile.csrf-token"];
2123
+ }
2124
+ if (validCookie) {
2125
+ return validCookie;
2126
+ }
2127
+ }
2128
+ if (initHeaders) {
2129
+ const cookies = getCookies(initHeaders);
2130
+ if (cookies) {
2131
+ return cookies["__Secure-nile.csrf-token"] || cookies["nile.csrf-token"];
2132
+ }
2133
+ }
2134
+ }
2135
+ var getCookies = (headers) => {
2136
+ if (!headers) return {};
2137
+ const cookieHeader = headers.get("cookie") || "";
2138
+ const setCookieHeaders = headers.get("set-cookie") || "";
2139
+ const allCookies = [
2140
+ ...cookieHeader.split("; "),
2141
+ // Regular 'cookie' header (semicolon-separated)
2142
+ ...setCookieHeaders.split(/,\s*(?=[^;, ]+=)/)
2143
+ // Smart split for 'set-cookie'
2144
+ ].filter(Boolean);
2145
+ return Object.fromEntries(
2146
+ allCookies.map((cookie) => {
2147
+ const [key12, ...val] = cookie.split("=");
2148
+ return [
2149
+ decodeURIComponent(key12.trim()),
2150
+ decodeURIComponent(val.join("=").trim())
2151
+ ];
2152
+ })
2153
+ );
2017
2154
  };
2018
2155
 
2019
2156
  // src/tenants/index.ts
@@ -2220,7 +2357,9 @@ var Api = class {
2220
2357
  paths;
2221
2358
  constructor(config) {
2222
2359
  this.config = config;
2223
- this.auth = new Auth(config);
2360
+ this.auth = new Auth(config, void 0, {
2361
+ resetHeaders: this.resetHeaders
2362
+ });
2224
2363
  this.users = new Users(config);
2225
2364
  this.tenants = new Tenants(config);
2226
2365
  this.routes = {
@@ -2250,7 +2389,7 @@ var Api = class {
2250
2389
  this.routes.USERS,
2251
2390
  this.routes.TENANTS,
2252
2391
  this.routes.SESSION,
2253
- this.routes.SIGNIN,
2392
+ `${this.routes.SIGNIN}/{provider}`,
2254
2393
  this.routes.PASSWORD_RESET,
2255
2394
  this.routes.PROVIDERS,
2256
2395
  this.routes.CSRF,
@@ -2266,27 +2405,47 @@ var Api = class {
2266
2405
  delete: [this.routes.TENANT_USER, this.routes.TENANT]
2267
2406
  };
2268
2407
  }
2269
- updateConfig(config) {
2408
+ reset = () => {
2409
+ this.users = new Users(this.config, this._headers);
2410
+ this.tenants = new Tenants(this.config, this._headers);
2411
+ this.auth = new Auth(this.config, this._headers, {
2412
+ resetHeaders: this.resetHeaders
2413
+ });
2414
+ };
2415
+ updateConfig = (config) => {
2270
2416
  this.config = config;
2271
2417
  this.handlers = Handlers(this.routes, config);
2272
- }
2418
+ };
2419
+ resetHeaders = (headers) => {
2420
+ this._headers = new Headers(headers ?? {});
2421
+ this.reset();
2422
+ };
2273
2423
  set headers(headers) {
2274
- this.users = new Users(this.config, headers);
2275
- this.tenants = new Tenants(this.config, headers);
2276
- this.auth = new Auth(this.config, headers);
2277
2424
  this._headers = headers;
2425
+ this.reset();
2278
2426
  }
2279
- async login(payload) {
2280
- this.headers = await serverLogin(this.config, this.handlers)(payload);
2427
+ get headers() {
2428
+ return this._headers;
2281
2429
  }
2282
- async session(req) {
2430
+ login = async (payload, config) => {
2431
+ const [headers, loginRes] = await serverLogin(
2432
+ this.config,
2433
+ this.handlers
2434
+ )(payload);
2435
+ this.headers = headers;
2436
+ if (config?.returnResponse) {
2437
+ return loginRes;
2438
+ }
2439
+ return void 0;
2440
+ };
2441
+ session = async (req) => {
2283
2442
  if (req instanceof Headers) {
2284
2443
  return this.auth.getSession(req);
2285
2444
  } else if (req instanceof Request) {
2286
2445
  return auth(req, this.config);
2287
2446
  }
2288
2447
  return this.auth.getSession(this._headers);
2289
- }
2448
+ };
2290
2449
  };
2291
2450
 
2292
2451
  // src/Server.ts