@factiii/auth 0.2.0 → 0.3.0

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.js CHANGED
@@ -323,6 +323,7 @@ function createAuthGuard(config, t) {
323
323
  clearAuthCookies(ctx.res, cookieSettings, storageKeys);
324
324
  if (config.hooks?.logError) {
325
325
  try {
326
+ const cookieHeader = ctx.headers.cookie;
326
327
  const contextInfo = {
327
328
  reason: description,
328
329
  sessionId,
@@ -330,6 +331,11 @@ function createAuthGuard(config, t) {
330
331
  ip: ctx.ip,
331
332
  userAgent: ctx.headers["user-agent"],
332
333
  ...path ? { path } : {},
334
+ // Diagnostic: was Cookie header present at all, and which keys were sent?
335
+ hasCookieHeader: Boolean(cookieHeader),
336
+ cookieKeys: cookieHeader ? cookieHeader.split(";").map((c) => c.trim().split("=")[0]).filter(Boolean) : [],
337
+ origin: ctx.headers.origin ?? null,
338
+ referer: ctx.headers.referer ?? null,
333
339
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
334
340
  };
335
341
  const combinedStack = [
@@ -1844,15 +1850,29 @@ var TwoFaProcedureFactory = class {
1844
1850
  const { pushToken } = input;
1845
1851
  const device = await this.config.prisma.device.findFirst({
1846
1852
  where: {
1847
- ...userId !== 0 && { users: { some: { id: userId } } },
1853
+ users: { some: { id: userId } },
1848
1854
  pushToken
1849
1855
  },
1850
1856
  select: { id: true }
1851
1857
  });
1852
1858
  if (device) {
1853
- await this.config.prisma.device.delete({
1854
- where: { id: device.id }
1859
+ await this.config.prisma.session.updateMany({
1860
+ where: { userId, deviceId: device.id },
1861
+ data: { deviceId: null }
1855
1862
  });
1863
+ await this.config.prisma.device.update({
1864
+ where: { id: device.id },
1865
+ data: { users: { disconnect: { id: userId } } }
1866
+ });
1867
+ const remainingUsers = await this.config.prisma.device.findUnique({
1868
+ where: { id: device.id },
1869
+ select: { users: { select: { id: true }, take: 1 } }
1870
+ });
1871
+ if (!remainingUsers?.users.length) {
1872
+ await this.config.prisma.device.delete({
1873
+ where: { id: device.id }
1874
+ });
1875
+ }
1856
1876
  }
1857
1877
  return { deregistered: true };
1858
1878
  });
package/dist/index.mjs CHANGED
@@ -267,6 +267,7 @@ function createAuthGuard(config, t) {
267
267
  clearAuthCookies(ctx.res, cookieSettings, storageKeys);
268
268
  if (config.hooks?.logError) {
269
269
  try {
270
+ const cookieHeader = ctx.headers.cookie;
270
271
  const contextInfo = {
271
272
  reason: description,
272
273
  sessionId,
@@ -274,6 +275,11 @@ function createAuthGuard(config, t) {
274
275
  ip: ctx.ip,
275
276
  userAgent: ctx.headers["user-agent"],
276
277
  ...path ? { path } : {},
278
+ // Diagnostic: was Cookie header present at all, and which keys were sent?
279
+ hasCookieHeader: Boolean(cookieHeader),
280
+ cookieKeys: cookieHeader ? cookieHeader.split(";").map((c) => c.trim().split("=")[0]).filter(Boolean) : [],
281
+ origin: ctx.headers.origin ?? null,
282
+ referer: ctx.headers.referer ?? null,
277
283
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
278
284
  };
279
285
  const combinedStack = [
@@ -1694,15 +1700,29 @@ var TwoFaProcedureFactory = class {
1694
1700
  const { pushToken } = input;
1695
1701
  const device = await this.config.prisma.device.findFirst({
1696
1702
  where: {
1697
- ...userId !== 0 && { users: { some: { id: userId } } },
1703
+ users: { some: { id: userId } },
1698
1704
  pushToken
1699
1705
  },
1700
1706
  select: { id: true }
1701
1707
  });
1702
1708
  if (device) {
1703
- await this.config.prisma.device.delete({
1704
- where: { id: device.id }
1709
+ await this.config.prisma.session.updateMany({
1710
+ where: { userId, deviceId: device.id },
1711
+ data: { deviceId: null }
1705
1712
  });
1713
+ await this.config.prisma.device.update({
1714
+ where: { id: device.id },
1715
+ data: { users: { disconnect: { id: userId } } }
1716
+ });
1717
+ const remainingUsers = await this.config.prisma.device.findUnique({
1718
+ where: { id: device.id },
1719
+ select: { users: { select: { id: true }, take: 1 } }
1720
+ });
1721
+ if (!remainingUsers?.users.length) {
1722
+ await this.config.prisma.device.delete({
1723
+ where: { id: device.id }
1724
+ });
1725
+ }
1706
1726
  }
1707
1727
  return { deregistered: true };
1708
1728
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@factiii/auth",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },