ideal-auth 0.7.0 → 1.0.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.
@@ -121,5 +121,22 @@ export function createAuthInstance(deps) {
121
121
  const session = await readSession();
122
122
  return session?.uid ?? null;
123
123
  },
124
+ async touch() {
125
+ const session = await readSession();
126
+ if (!session)
127
+ return;
128
+ const maxAge = session.exp - session.iat;
129
+ const now = Math.floor(Date.now() / 1000);
130
+ const newPayload = {
131
+ uid: session.uid,
132
+ iat: session.iat, // preserve original issued-at for passwordChangedAt checks
133
+ exp: now + maxAge,
134
+ ...(session.data !== undefined && { data: session.data }),
135
+ };
136
+ const sealed = await seal(newPayload, deps.secret);
137
+ const opts = buildCookieOptions(maxAge, deps.cookieOptions);
138
+ await deps.cookie.set(deps.cookieName, sealed, opts);
139
+ cachedPayload = newPayload;
140
+ },
124
141
  };
125
142
  }
package/dist/types.d.ts CHANGED
@@ -86,6 +86,8 @@ export interface AuthInstance<TUser extends AnyUser = AnyUser> {
86
86
  check(): Promise<boolean>;
87
87
  user(): Promise<TUser | null>;
88
88
  id(): Promise<string | null>;
89
+ /** Re-seal the session cookie with a fresh expiry. No database call needed. Does nothing if no valid session exists. */
90
+ touch(): Promise<void>;
89
91
  }
90
92
  export interface HashInstance {
91
93
  make(password: string): Promise<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ideal-auth",
3
- "version": "0.7.0",
3
+ "version": "1.0.0",
4
4
  "description": "Auth primitives for the JS ecosystem. Zero framework dependencies.",
5
5
  "scripts": {
6
6
  "build": "tsc",
@@ -51,5 +51,32 @@
51
51
  "type": "git",
52
52
  "url": "git+https://github.com/ramonmalcolm10/ideal-auth.git"
53
53
  },
54
- "license": "MIT"
54
+ "license": "MIT",
55
+ "keywords": [
56
+ "auth",
57
+ "authentication",
58
+ "session",
59
+ "cookie",
60
+ "login",
61
+ "password",
62
+ "bcrypt",
63
+ "argon2",
64
+ "hash",
65
+ "totp",
66
+ "2fa",
67
+ "two-factor",
68
+ "mfa",
69
+ "rate-limit",
70
+ "csrf",
71
+ "encryption",
72
+ "iron-session",
73
+ "nextjs",
74
+ "sveltekit",
75
+ "express",
76
+ "hono",
77
+ "nuxt",
78
+ "bun",
79
+ "passkey",
80
+ "webauthn"
81
+ ]
55
82
  }
@@ -154,6 +154,7 @@ Key rules:
154
154
  | `check()` | `Promise<boolean>` | Is the session valid? (fast, cached) |
155
155
  | `user()` | `Promise<TUser \| null>` | Get the authenticated user (from DB with `resolveUser`, or from cookie with `sessionFields`) |
156
156
  | `id()` | `Promise<string \| null>` | Get the authenticated user's ID |
157
+ | `touch()` | `Promise<void>` | Re-seal the session cookie with a fresh expiry. No database call needed. |
157
158
 
158
159
  #### LoginOptions
159
160
 
@@ -166,6 +167,20 @@ type LoginOptions = {
166
167
  };
167
168
  ```
168
169
 
170
+ #### Session Extension with `touch()`
171
+
172
+ Sessions have a fixed expiry. Call `touch()` in middleware to extend the session for active users:
173
+
174
+ ```typescript
175
+ // In middleware — where cookie writes are allowed
176
+ const session = auth();
177
+ if (await session.check()) {
178
+ await session.touch(); // re-seals cookie with fresh exp
179
+ }
180
+ ```
181
+
182
+ `touch()` re-seals with the same `maxAge` as the original session. No database call needed. `check()`, `user()`, and `id()` are read-only — they never write cookies. Only call `touch()` where cookie writes are allowed (middleware, route handlers, server actions — NOT Server Components).
183
+
169
184
  #### `attempt()` — Two Modes
170
185
 
171
186
  **Laravel-style (recommended):** Provide `hash` and `resolveUserByCredentials`. The `attempt()` method strips the credential key (default `'password'`) from credentials, looks up the user with remaining fields, and verifies the hash automatically.