@bivola/refresh-auth 1.1.2 → 1.1.3

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.
@@ -36,7 +36,7 @@ export const loginEndpoint = (options)=>({
36
36
  });
37
37
  },
38
38
  method: 'post',
39
- path: `/${options.entity_slug}/auth/login`
39
+ path: `/auth/login`
40
40
  });
41
41
 
42
42
  //# sourceMappingURL=login.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/endpoints/login.ts"],"sourcesContent":["import type { Endpoint } from 'payload'\n\nimport type { AuthRefreshPluginOptions } from '../index'\n\nimport { createRefreshToken } from '../utils/crypto'\nimport { getRequestMeta } from '../utils/getRequestMeta'\n\ntype LoginEndpointOptions = Pick<\n AuthRefreshPluginOptions,\n 'entity_slug' | 'identifier_field' | 'pepper' | 'refreshTokenTTL'\n>\n\nexport const loginEndpoint = (options: LoginEndpointOptions): Endpoint => ({\n handler: async (req) => {\n const { deviceId, identifier, password } = (await req.json?.()) || {}\n\n if (!identifier || !password) {\n return Response.json({ message: 'Identifier and password are required.' }, { status: 400 })\n }\n\n const login = await req.payload.login({\n collection: options.entity_slug,\n data: {\n [options.identifier_field]: identifier,\n password,\n } as any,\n })\n\n const { token, tokenHash } = createRefreshToken(options.pepper)\n\n await req.payload.create({\n collection: 'refresh-tokens',\n data: {\n deviceId,\n entity: login.user.id,\n expiresAt: new Date(Date.now() + options.refreshTokenTTL * 24 * 60 * 60 * 1000),\n lastUsedAt: new Date(),\n tokenHash,\n ...getRequestMeta(req),\n },\n })\n\n return Response.json({\n access_token: login.token,\n refresh_token: token,\n user: login.user,\n })\n },\n method: 'post',\n path: `/${options.entity_slug}/auth/login`,\n})\n"],"names":["createRefreshToken","getRequestMeta","loginEndpoint","options","handler","req","deviceId","identifier","password","json","Response","message","status","login","payload","collection","entity_slug","data","identifier_field","token","tokenHash","pepper","create","entity","user","id","expiresAt","Date","now","refreshTokenTTL","lastUsedAt","access_token","refresh_token","method","path"],"mappings":"AAIA,SAASA,kBAAkB,QAAQ,kBAAiB;AACpD,SAASC,cAAc,QAAQ,0BAAyB;AAOxD,OAAO,MAAMC,gBAAgB,CAACC,UAA6C,CAAA;QACzEC,SAAS,OAAOC;YACd,MAAM,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAG,AAAC,MAAMH,IAAII,IAAI,QAAS,CAAC;YAEpE,IAAI,CAACF,cAAc,CAACC,UAAU;gBAC5B,OAAOE,SAASD,IAAI,CAAC;oBAAEE,SAAS;gBAAwC,GAAG;oBAAEC,QAAQ;gBAAI;YAC3F;YAEA,MAAMC,QAAQ,MAAMR,IAAIS,OAAO,CAACD,KAAK,CAAC;gBACpCE,YAAYZ,QAAQa,WAAW;gBAC/BC,MAAM;oBACJ,CAACd,QAAQe,gBAAgB,CAAC,EAAEX;oBAC5BC;gBACF;YACF;YAEA,MAAM,EAAEW,KAAK,EAAEC,SAAS,EAAE,GAAGpB,mBAAmBG,QAAQkB,MAAM;YAE9D,MAAMhB,IAAIS,OAAO,CAACQ,MAAM,CAAC;gBACvBP,YAAY;gBACZE,MAAM;oBACJX;oBACAiB,QAAQV,MAAMW,IAAI,CAACC,EAAE;oBACrBC,WAAW,IAAIC,KAAKA,KAAKC,GAAG,KAAKzB,QAAQ0B,eAAe,GAAG,KAAK,KAAK,KAAK;oBAC1EC,YAAY,IAAIH;oBAChBP;oBACA,GAAGnB,eAAeI,IAAI;gBACxB;YACF;YAEA,OAAOK,SAASD,IAAI,CAAC;gBACnBsB,cAAclB,MAAMM,KAAK;gBACzBa,eAAeb;gBACfK,MAAMX,MAAMW,IAAI;YAClB;QACF;QACAS,QAAQ;QACRC,MAAM,CAAC,CAAC,EAAE/B,QAAQa,WAAW,CAAC,WAAW,CAAC;IAC5C,CAAA,EAAE"}
1
+ {"version":3,"sources":["../../src/endpoints/login.ts"],"sourcesContent":["import type { Endpoint } from 'payload'\n\nimport type { AuthRefreshPluginOptions } from '../index'\n\nimport { createRefreshToken } from '../utils/crypto'\nimport { getRequestMeta } from '../utils/getRequestMeta'\n\ntype LoginEndpointOptions = Pick<\n AuthRefreshPluginOptions,\n 'entity_slug' | 'identifier_field' | 'pepper' | 'refreshTokenTTL'\n>\n\nexport const loginEndpoint = (options: LoginEndpointOptions): Endpoint => ({\n handler: async (req) => {\n const { deviceId, identifier, password } = (await req.json?.()) || {}\n\n if (!identifier || !password) {\n return Response.json({ message: 'Identifier and password are required.' }, { status: 400 })\n }\n\n const login = await req.payload.login({\n collection: options.entity_slug,\n data: {\n [options.identifier_field]: identifier,\n password,\n } as any,\n })\n\n const { token, tokenHash } = createRefreshToken(options.pepper)\n\n await req.payload.create({\n collection: 'refresh-tokens',\n data: {\n deviceId,\n entity: login.user.id,\n expiresAt: new Date(Date.now() + options.refreshTokenTTL * 24 * 60 * 60 * 1000),\n lastUsedAt: new Date(),\n tokenHash,\n ...getRequestMeta(req),\n },\n })\n\n return Response.json({\n access_token: login.token,\n refresh_token: token,\n user: login.user,\n })\n },\n method: 'post',\n path: `/auth/login`,\n})\n"],"names":["createRefreshToken","getRequestMeta","loginEndpoint","options","handler","req","deviceId","identifier","password","json","Response","message","status","login","payload","collection","entity_slug","data","identifier_field","token","tokenHash","pepper","create","entity","user","id","expiresAt","Date","now","refreshTokenTTL","lastUsedAt","access_token","refresh_token","method","path"],"mappings":"AAIA,SAASA,kBAAkB,QAAQ,kBAAiB;AACpD,SAASC,cAAc,QAAQ,0BAAyB;AAOxD,OAAO,MAAMC,gBAAgB,CAACC,UAA6C,CAAA;QACzEC,SAAS,OAAOC;YACd,MAAM,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAG,AAAC,MAAMH,IAAII,IAAI,QAAS,CAAC;YAEpE,IAAI,CAACF,cAAc,CAACC,UAAU;gBAC5B,OAAOE,SAASD,IAAI,CAAC;oBAAEE,SAAS;gBAAwC,GAAG;oBAAEC,QAAQ;gBAAI;YAC3F;YAEA,MAAMC,QAAQ,MAAMR,IAAIS,OAAO,CAACD,KAAK,CAAC;gBACpCE,YAAYZ,QAAQa,WAAW;gBAC/BC,MAAM;oBACJ,CAACd,QAAQe,gBAAgB,CAAC,EAAEX;oBAC5BC;gBACF;YACF;YAEA,MAAM,EAAEW,KAAK,EAAEC,SAAS,EAAE,GAAGpB,mBAAmBG,QAAQkB,MAAM;YAE9D,MAAMhB,IAAIS,OAAO,CAACQ,MAAM,CAAC;gBACvBP,YAAY;gBACZE,MAAM;oBACJX;oBACAiB,QAAQV,MAAMW,IAAI,CAACC,EAAE;oBACrBC,WAAW,IAAIC,KAAKA,KAAKC,GAAG,KAAKzB,QAAQ0B,eAAe,GAAG,KAAK,KAAK,KAAK;oBAC1EC,YAAY,IAAIH;oBAChBP;oBACA,GAAGnB,eAAeI,IAAI;gBACxB;YACF;YAEA,OAAOK,SAASD,IAAI,CAAC;gBACnBsB,cAAclB,MAAMM,KAAK;gBACzBa,eAAeb;gBACfK,MAAMX,MAAMW,IAAI;YAClB;QACF;QACAS,QAAQ;QACRC,MAAM,CAAC,WAAW,CAAC;IACrB,CAAA,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bivola/refresh-auth",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "A blank template to get started with Payload 3.0",
5
5
  "license": "MIT",
6
6
  "type": "module",