@niledatabase/server 4.0.0-alpha.12 → 4.0.0-alpha.14

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.mts CHANGED
@@ -72,10 +72,10 @@ type NilePoolConfig = PoolConfig & {
72
72
  afterCreate?: AfterCreate;
73
73
  };
74
74
  type LoggerType = {
75
- info?: (args: unknown[]) => void;
76
- warn?: (args: unknown[]) => void;
77
- error?: (args: unknown[]) => void;
78
- debug?: (args: unknown[]) => void;
75
+ info?: (args: unknown | unknown[]) => void;
76
+ warn?: (args: unknown | unknown[]) => void;
77
+ error?: (args: unknown | unknown[]) => void;
78
+ debug?: (args: unknown | unknown[]) => void;
79
79
  };
80
80
  type ServerConfig = {
81
81
  databaseId?: string;
@@ -215,20 +215,25 @@ type NileRequest<T> = NRequest<T> | T;
215
215
 
216
216
  declare class Auth extends Config {
217
217
  headers?: Headers;
218
- constructor(config: Config, headers?: Headers);
218
+ resetHeaders?: () => void;
219
+ constructor(config: Config, headers?: Headers, params?: {
220
+ resetHeaders: () => void;
221
+ });
219
222
  handleHeaders(init?: RequestInit): RequestInit | undefined;
220
223
  get sessionUrl(): string;
221
- getSession: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<JWT | ActiveSession | Response | undefined>;
224
+ getSession: <T = JWT | ActiveSession | Response | undefined>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
222
225
  get getCsrfUrl(): string;
223
- getCsrf(req: NileRequest<void> | Headers, init?: RequestInit): Promise<JSON | Response>;
226
+ getCsrf<T = Response | JSON>(req: NileRequest<void> | Headers, init?: RequestInit, raw?: boolean): Promise<T>;
224
227
  get listProvidersUrl(): string;
225
- listProviders: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<Response | {
228
+ listProviders: <T = Response | {
226
229
  [key: string]: Provider;
227
- }>;
230
+ }>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
228
231
  get signOutUrl(): string;
229
- signOut: (req: NileRequest<void | {
232
+ signOut: <T = Response | {
233
+ url: string;
234
+ }>(req: NileRequest<void | {
230
235
  callbackUrl?: string;
231
- }> | Headers, init?: RequestInit) => Promise<Response | JSON>;
236
+ }> | Headers, init?: RequestInit) => Promise<T>;
232
237
  }
233
238
 
234
239
  declare class Tenants extends Config {
@@ -237,18 +242,18 @@ declare class Tenants extends Config {
237
242
  handleHeaders(init?: RequestInit): RequestInit | undefined;
238
243
  get tenantsUrl(): string;
239
244
  get tenantUrl(): string;
240
- createTenant: (req: NileRequest<{
245
+ createTenant: <T = Tenant | Response>(req: NileRequest<{
241
246
  name: string;
242
- }> | Headers | string, init?: RequestInit) => Promise<Tenant | Response>;
243
- getTenant: (req: NileRequest<{
247
+ }> | Headers | string, init?: RequestInit) => Promise<T>;
248
+ getTenant: <T = Tenant | Response>(req: NileRequest<{
244
249
  id: string;
245
- }> | Headers | string | void, init?: RequestInit) => Promise<Tenant | Response>;
250
+ }> | Headers | string | void, init?: RequestInit) => Promise<T>;
246
251
  get tenantListUrl(): string;
247
- listTenants: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<Tenant[] | Response>;
248
- deleteTenant: (req: NileRequest<void> | Headers | string, init?: RequestInit) => Promise<Response>;
249
- updateTenant: (req: NileRequest<void> | Headers | {
252
+ listTenants: <T = Tenant[] | Response>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
253
+ deleteTenant: <T = Response>(req: NileRequest<void> | Headers | string, init?: RequestInit) => Promise<T>;
254
+ updateTenant: <T = Tenant | Response>(req: NileRequest<void> | Headers | {
250
255
  name: string;
251
- }, init?: RequestInit) => Promise<Tenant | Response>;
256
+ }, init?: RequestInit) => Promise<T>;
252
257
  }
253
258
 
254
259
  declare class Users extends Config {
@@ -259,21 +264,21 @@ declare class Users extends Config {
259
264
  get linkUsersUrl(): string;
260
265
  get tenantUserUrl(): string;
261
266
  handleHeaders(init?: RequestInit): RequestInit | undefined;
262
- createUser: (req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => Promise<User | Response>;
263
- createTenantUser: (req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => Promise<User | Response>;
264
- updateUser: (req: NileRequest<Partial<Omit<User, "email" | "tenants" | "created" | "updated">>>, init?: RequestInit) => Promise<User | Response>;
265
- listUsers: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<User[] | Response>;
266
- linkUser: (req: NileRequest<{
267
+ createUser: <T = User | Response>(req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => Promise<T>;
268
+ createTenantUser: <T = User | Response>(req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => Promise<T>;
269
+ updateUser: <T = User[] | Response>(req: NileRequest<Partial<Omit<User, "email" | "tenants" | "created" | "updated">>>, init?: RequestInit) => Promise<T>;
270
+ listUsers: <T = User[] | Response>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
271
+ linkUser: <T = User | Response>(req: NileRequest<{
267
272
  id: string;
268
273
  tenantId?: string;
269
- }> | Headers | string, init?: RequestInit) => Promise<User | Response>;
270
- unlinkUser: (req: NileRequest<{
274
+ }> | Headers | string, init?: RequestInit) => Promise<T>;
275
+ unlinkUser: <T = Response>(req: NileRequest<{
271
276
  id: string;
272
277
  tenantId?: string;
273
- }> | Headers | string, init?: RequestInit) => Promise<Response>;
278
+ }> | Headers | string, init?: RequestInit) => Promise<T>;
274
279
  get meUrl(): string;
275
280
  me: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<User | Response>;
276
- updateMe: (req: NileRequest<Partial<Omit<User, "email" | "id" | "tenants" | "created" | "updated">>> | Headers, init?: RequestInit) => Promise<User | Response>;
281
+ updateMe: <T = User | Response>(req: NileRequest<Partial<Omit<User, "email" | "id" | "tenants" | "created" | "updated">>> | Headers, init?: RequestInit) => Promise<T>;
277
282
  }
278
283
 
279
284
  declare class Api {
@@ -296,13 +301,18 @@ declare class Api {
296
301
  put: string[];
297
302
  };
298
303
  constructor(config: Config);
299
- updateConfig(config: Config): void;
304
+ reset: () => void;
305
+ updateConfig: (config: Config) => void;
306
+ resetHeaders: () => void;
300
307
  set headers(headers: Headers);
301
- login(payload: {
308
+ get headers(): Headers | undefined;
309
+ login: (payload: {
302
310
  email: string;
303
311
  password: string;
304
- }): Promise<void>;
305
- session(req?: Request | Headers | null | undefined): Promise<Response | JWT | ActiveSession | null | undefined>;
312
+ }, config?: {
313
+ setCookie?: boolean;
314
+ }) => Promise<void>;
315
+ session: (req?: Request | Headers | null | undefined) => Promise<Response | JWT | ActiveSession | null | undefined>;
306
316
  }
307
317
 
308
318
  declare class Server {
package/dist/index.d.ts CHANGED
@@ -72,10 +72,10 @@ type NilePoolConfig = PoolConfig & {
72
72
  afterCreate?: AfterCreate;
73
73
  };
74
74
  type LoggerType = {
75
- info?: (args: unknown[]) => void;
76
- warn?: (args: unknown[]) => void;
77
- error?: (args: unknown[]) => void;
78
- debug?: (args: unknown[]) => void;
75
+ info?: (args: unknown | unknown[]) => void;
76
+ warn?: (args: unknown | unknown[]) => void;
77
+ error?: (args: unknown | unknown[]) => void;
78
+ debug?: (args: unknown | unknown[]) => void;
79
79
  };
80
80
  type ServerConfig = {
81
81
  databaseId?: string;
@@ -215,20 +215,25 @@ type NileRequest<T> = NRequest<T> | T;
215
215
 
216
216
  declare class Auth extends Config {
217
217
  headers?: Headers;
218
- constructor(config: Config, headers?: Headers);
218
+ resetHeaders?: () => void;
219
+ constructor(config: Config, headers?: Headers, params?: {
220
+ resetHeaders: () => void;
221
+ });
219
222
  handleHeaders(init?: RequestInit): RequestInit | undefined;
220
223
  get sessionUrl(): string;
221
- getSession: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<JWT | ActiveSession | Response | undefined>;
224
+ getSession: <T = JWT | ActiveSession | Response | undefined>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
222
225
  get getCsrfUrl(): string;
223
- getCsrf(req: NileRequest<void> | Headers, init?: RequestInit): Promise<JSON | Response>;
226
+ getCsrf<T = Response | JSON>(req: NileRequest<void> | Headers, init?: RequestInit, raw?: boolean): Promise<T>;
224
227
  get listProvidersUrl(): string;
225
- listProviders: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<Response | {
228
+ listProviders: <T = Response | {
226
229
  [key: string]: Provider;
227
- }>;
230
+ }>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
228
231
  get signOutUrl(): string;
229
- signOut: (req: NileRequest<void | {
232
+ signOut: <T = Response | {
233
+ url: string;
234
+ }>(req: NileRequest<void | {
230
235
  callbackUrl?: string;
231
- }> | Headers, init?: RequestInit) => Promise<Response | JSON>;
236
+ }> | Headers, init?: RequestInit) => Promise<T>;
232
237
  }
233
238
 
234
239
  declare class Tenants extends Config {
@@ -237,18 +242,18 @@ declare class Tenants extends Config {
237
242
  handleHeaders(init?: RequestInit): RequestInit | undefined;
238
243
  get tenantsUrl(): string;
239
244
  get tenantUrl(): string;
240
- createTenant: (req: NileRequest<{
245
+ createTenant: <T = Tenant | Response>(req: NileRequest<{
241
246
  name: string;
242
- }> | Headers | string, init?: RequestInit) => Promise<Tenant | Response>;
243
- getTenant: (req: NileRequest<{
247
+ }> | Headers | string, init?: RequestInit) => Promise<T>;
248
+ getTenant: <T = Tenant | Response>(req: NileRequest<{
244
249
  id: string;
245
- }> | Headers | string | void, init?: RequestInit) => Promise<Tenant | Response>;
250
+ }> | Headers | string | void, init?: RequestInit) => Promise<T>;
246
251
  get tenantListUrl(): string;
247
- listTenants: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<Tenant[] | Response>;
248
- deleteTenant: (req: NileRequest<void> | Headers | string, init?: RequestInit) => Promise<Response>;
249
- updateTenant: (req: NileRequest<void> | Headers | {
252
+ listTenants: <T = Tenant[] | Response>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
253
+ deleteTenant: <T = Response>(req: NileRequest<void> | Headers | string, init?: RequestInit) => Promise<T>;
254
+ updateTenant: <T = Tenant | Response>(req: NileRequest<void> | Headers | {
250
255
  name: string;
251
- }, init?: RequestInit) => Promise<Tenant | Response>;
256
+ }, init?: RequestInit) => Promise<T>;
252
257
  }
253
258
 
254
259
  declare class Users extends Config {
@@ -259,21 +264,21 @@ declare class Users extends Config {
259
264
  get linkUsersUrl(): string;
260
265
  get tenantUserUrl(): string;
261
266
  handleHeaders(init?: RequestInit): RequestInit | undefined;
262
- createUser: (req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => Promise<User | Response>;
263
- createTenantUser: (req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => Promise<User | Response>;
264
- updateUser: (req: NileRequest<Partial<Omit<User, "email" | "tenants" | "created" | "updated">>>, init?: RequestInit) => Promise<User | Response>;
265
- listUsers: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<User[] | Response>;
266
- linkUser: (req: NileRequest<{
267
+ createUser: <T = User | Response>(req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => Promise<T>;
268
+ createTenantUser: <T = User | Response>(req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => Promise<T>;
269
+ updateUser: <T = User[] | Response>(req: NileRequest<Partial<Omit<User, "email" | "tenants" | "created" | "updated">>>, init?: RequestInit) => Promise<T>;
270
+ listUsers: <T = User[] | Response>(req: NileRequest<void> | Headers, init?: RequestInit) => Promise<T>;
271
+ linkUser: <T = User | Response>(req: NileRequest<{
267
272
  id: string;
268
273
  tenantId?: string;
269
- }> | Headers | string, init?: RequestInit) => Promise<User | Response>;
270
- unlinkUser: (req: NileRequest<{
274
+ }> | Headers | string, init?: RequestInit) => Promise<T>;
275
+ unlinkUser: <T = Response>(req: NileRequest<{
271
276
  id: string;
272
277
  tenantId?: string;
273
- }> | Headers | string, init?: RequestInit) => Promise<Response>;
278
+ }> | Headers | string, init?: RequestInit) => Promise<T>;
274
279
  get meUrl(): string;
275
280
  me: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<User | Response>;
276
- updateMe: (req: NileRequest<Partial<Omit<User, "email" | "id" | "tenants" | "created" | "updated">>> | Headers, init?: RequestInit) => Promise<User | Response>;
281
+ updateMe: <T = User | Response>(req: NileRequest<Partial<Omit<User, "email" | "id" | "tenants" | "created" | "updated">>> | Headers, init?: RequestInit) => Promise<T>;
277
282
  }
278
283
 
279
284
  declare class Api {
@@ -296,13 +301,18 @@ declare class Api {
296
301
  put: string[];
297
302
  };
298
303
  constructor(config: Config);
299
- updateConfig(config: Config): void;
304
+ reset: () => void;
305
+ updateConfig: (config: Config) => void;
306
+ resetHeaders: () => void;
300
307
  set headers(headers: Headers);
301
- login(payload: {
308
+ get headers(): Headers | undefined;
309
+ login: (payload: {
302
310
  email: string;
303
311
  password: string;
304
- }): Promise<void>;
305
- session(req?: Request | Headers | null | undefined): Promise<Response | JWT | ActiveSession | null | undefined>;
312
+ }, config?: {
313
+ setCookie?: boolean;
314
+ }) => Promise<void>;
315
+ session: (req?: Request | Headers | null | undefined) => Promise<Response | JWT | ActiveSession | null | undefined>;
306
316
  }
307
317
 
308
318
  declare class Server {
package/dist/index.js CHANGED
@@ -1856,8 +1856,11 @@ var Requester = class extends Config {
1856
1856
  }
1857
1857
  return response;
1858
1858
  }
1859
- async get(req, url, init) {
1859
+ async get(req, url, init, raw = false) {
1860
1860
  const response = await this.request("GET", url, req, init);
1861
+ if (raw) {
1862
+ return response;
1863
+ }
1861
1864
  if (response && response.status >= 200 && response.status < 300) {
1862
1865
  const cloned = response.clone();
1863
1866
  try {
@@ -1892,7 +1895,7 @@ function serverLogin(config, handlers) {
1892
1895
  return async function login({
1893
1896
  email,
1894
1897
  password
1895
- }) {
1898
+ }, loginConfig) {
1896
1899
  if (!email || !password) {
1897
1900
  throw new Error("Server side login requires a user email and password.");
1898
1901
  }
@@ -1967,6 +1970,9 @@ function serverLogin(config, handlers) {
1967
1970
  if (!authCookie) {
1968
1971
  throw new Error("authentication failed");
1969
1972
  }
1973
+ if (loginConfig?.setCookie) {
1974
+ return loginRes;
1975
+ }
1970
1976
  const [, token] = /((__Secure-)?nile\.session-token=.+?);/.exec(authCookie) ?? [];
1971
1977
  if (!token) {
1972
1978
  error("Unable to obtain auth token", { authCookie });
@@ -1982,14 +1988,24 @@ function serverLogin(config, handlers) {
1982
1988
  }
1983
1989
  var Auth = class extends Config {
1984
1990
  headers;
1985
- constructor(config, headers) {
1991
+ resetHeaders;
1992
+ constructor(config, headers, params) {
1986
1993
  super(config);
1987
1994
  this.headers = headers;
1995
+ this.resetHeaders = params?.resetHeaders;
1988
1996
  }
1989
1997
  handleHeaders(init) {
1990
1998
  if (this.headers) {
1991
1999
  const cburl = getCallbackUrl2(this.headers);
1992
- this.headers.set(X_NILE_ORIGIN, new URL(cburl).origin);
2000
+ if (cburl) {
2001
+ try {
2002
+ this.headers.set(X_NILE_ORIGIN, new URL(cburl).origin);
2003
+ } catch (e) {
2004
+ if (this.logger?.debug) {
2005
+ this.logger.debug("Invalid URL supplied by cookie header");
2006
+ }
2007
+ }
2008
+ }
1993
2009
  if (init) {
1994
2010
  init.headers = new Headers({ ...this.headers, ...init?.headers });
1995
2011
  return init;
@@ -2017,10 +2033,10 @@ var Auth = class extends Config {
2017
2033
  get getCsrfUrl() {
2018
2034
  return "/auth/csrf";
2019
2035
  }
2020
- async getCsrf(req, init) {
2036
+ async getCsrf(req, init, raw = false) {
2021
2037
  const _requester = new Requester(this);
2022
2038
  const _init = this.handleHeaders(init);
2023
- return await _requester.get(req, this.getCsrfUrl, _init);
2039
+ return await _requester.get(req, this.getCsrfUrl, _init, raw);
2024
2040
  }
2025
2041
  get listProvidersUrl() {
2026
2042
  return "/auth/providers";
@@ -2036,35 +2052,71 @@ var Auth = class extends Config {
2036
2052
  signOut = async (req, init) => {
2037
2053
  const _requester = new Requester(this);
2038
2054
  const _init = this.handleHeaders(init);
2039
- const csrf = await this.getCsrf(req);
2055
+ const csrf = await this.getCsrf(
2056
+ req,
2057
+ void 0,
2058
+ true
2059
+ );
2060
+ const csrfHeader = getCsrfToken(csrf.headers);
2040
2061
  const callbackUrl = req && "callbackUrl" in req ? String(req.callbackUrl) : "/";
2041
- if (csrf instanceof Request) {
2042
- return csrf;
2043
- }
2044
- const csrfToken = "csrfToken" in csrf ? String(csrf.csrfToken) : "";
2045
- if (!csrfToken) {
2062
+ if (!csrfHeader) {
2046
2063
  return new Response("Request blocked", { status: 400 });
2047
2064
  }
2048
- return await _requester.post(req, this.signOutUrl, {
2065
+ const headers = new Headers(_init?.headers);
2066
+ const { csrfToken } = await csrf.json() ?? {};
2067
+ const cooks = getCookies(headers);
2068
+ if (csrfHeader) {
2069
+ if (cooks["__Secure-nile.csrf-token"]) {
2070
+ cooks["__Secure-nile.csrf-token"] = encodeURIComponent(csrfHeader);
2071
+ }
2072
+ if (cooks["nile.csrf-token"]) {
2073
+ cooks["nile.csrf-token"] = encodeURIComponent(csrfHeader);
2074
+ }
2075
+ }
2076
+ headers.set(
2077
+ "cookie",
2078
+ Object.keys(cooks).map((key12) => `${key12}=${cooks[key12]}`).join("; ")
2079
+ );
2080
+ const res = await _requester.post(req, this.signOutUrl, {
2049
2081
  method: "post",
2050
2082
  body: JSON.stringify({
2051
2083
  csrfToken,
2052
2084
  callbackUrl,
2053
2085
  json: String(true)
2054
2086
  }),
2055
- ..._init
2087
+ ..._init,
2088
+ headers
2056
2089
  });
2090
+ this.resetHeaders && this.resetHeaders();
2091
+ return res;
2057
2092
  };
2058
2093
  };
2059
2094
  function getCallbackUrl2(headers) {
2060
2095
  if (headers) {
2061
- const cookieHeader = headers.get("cookie") || "";
2062
- const cookies = Object.fromEntries(
2063
- cookieHeader.split("; ").map((cookie) => cookie.split("=").map(decodeURIComponent))
2064
- );
2065
- return cookies["__Secure-nile.callback-url"] || cookies["nile.callback-url"];
2096
+ const cookies = getCookies(headers);
2097
+ if (cookies) {
2098
+ return cookies["__Secure-nile.callback-url"] || cookies["nile.callback-url"];
2099
+ }
2066
2100
  }
2067
2101
  }
2102
+ function getCsrfToken(headers) {
2103
+ if (headers) {
2104
+ const cookies = getCookies(headers);
2105
+ if (cookies) {
2106
+ return cookies["__Secure-nile.csrf-token"] || cookies["nile.csrf-token"];
2107
+ }
2108
+ }
2109
+ }
2110
+ var getCookies = (headers) => {
2111
+ if (!headers) return {};
2112
+ const cookieHeader = headers.get("cookie") || headers.get("set-cookie");
2113
+ if (!cookieHeader) return {};
2114
+ return Object.fromEntries(
2115
+ cookieHeader.split(/,\s*(?=[^;]+=[^;,]+)/).flatMap(
2116
+ (cookie) => cookie.split("; ")[0].split("=").length === 2 ? [cookie.split("; ")[0].split("=").map(decodeURIComponent)] : []
2117
+ )
2118
+ );
2119
+ };
2068
2120
 
2069
2121
  // src/tenants/index.ts
2070
2122
  var Tenants = class extends Config {
@@ -2270,7 +2322,9 @@ var Api = class {
2270
2322
  paths;
2271
2323
  constructor(config) {
2272
2324
  this.config = config;
2273
- this.auth = new Auth(config);
2325
+ this.auth = new Auth(config, void 0, {
2326
+ resetHeaders: this.resetHeaders
2327
+ });
2274
2328
  this.users = new Users(config);
2275
2329
  this.tenants = new Tenants(config);
2276
2330
  this.routes = {
@@ -2316,27 +2370,42 @@ var Api = class {
2316
2370
  delete: [this.routes.TENANT_USER, this.routes.TENANT]
2317
2371
  };
2318
2372
  }
2319
- updateConfig(config) {
2373
+ reset = () => {
2374
+ this.users = new Users(this.config, this._headers);
2375
+ this.tenants = new Tenants(this.config, this._headers);
2376
+ this.auth = new Auth(this.config, this._headers, {
2377
+ resetHeaders: this.resetHeaders
2378
+ });
2379
+ };
2380
+ updateConfig = (config) => {
2320
2381
  this.config = config;
2321
2382
  this.handlers = Handlers(this.routes, config);
2322
- }
2383
+ };
2384
+ resetHeaders = () => {
2385
+ this._headers = new Headers();
2386
+ this.reset();
2387
+ };
2323
2388
  set headers(headers) {
2324
- this.users = new Users(this.config, headers);
2325
- this.tenants = new Tenants(this.config, headers);
2326
- this.auth = new Auth(this.config, headers);
2327
2389
  this._headers = headers;
2390
+ this.reset();
2328
2391
  }
2329
- async login(payload) {
2330
- this.headers = await serverLogin(this.config, this.handlers)(payload);
2392
+ get headers() {
2393
+ return this._headers;
2331
2394
  }
2332
- async session(req) {
2395
+ login = async (payload, config) => {
2396
+ this.headers = await serverLogin(this.config, this.handlers)(
2397
+ payload,
2398
+ config
2399
+ );
2400
+ };
2401
+ session = async (req) => {
2333
2402
  if (req instanceof Headers) {
2334
2403
  return this.auth.getSession(req);
2335
2404
  } else if (req instanceof Request) {
2336
2405
  return auth(req, this.config);
2337
2406
  }
2338
2407
  return this.auth.getSession(this._headers);
2339
- }
2408
+ };
2340
2409
  };
2341
2410
 
2342
2411
  // src/Server.ts