|
2 | 2 |
|
3 | 3 | import { ObjectKernel, getEnv } from '@objectstack/core'; |
4 | 4 | import { CoreServiceName } from '@objectstack/spec/system'; |
| 5 | +import { randomUUID } from 'crypto'; |
5 | 6 |
|
6 | 7 | export interface HttpProtocolContext { |
7 | 8 | request: any; |
@@ -202,32 +203,33 @@ export class HttpDispatcher { |
202 | 203 | */ |
203 | 204 | private mockAuthFallback(path: string, method: string, body: any): HttpDispatcherResult { |
204 | 205 | const m = method.toUpperCase(); |
| 206 | + const MOCK_SESSION_EXPIRY_MS = 86_400_000; // 24 hours |
205 | 207 |
|
206 | 208 | // POST sign-up/email |
207 | 209 | if ((path === 'sign-up/email' || path === 'register') && m === 'POST') { |
208 | | - const id = `mock_${Date.now()}`; |
| 210 | + const id = `mock_${randomUUID()}`; |
209 | 211 | return { |
210 | 212 | handled: true, |
211 | 213 | response: { |
212 | 214 | status: 200, |
213 | 215 | body: { |
214 | 216 | user: { id, name: body?.name || 'Mock User', email: body?.email || 'mock@test.local', emailVerified: false, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() }, |
215 | | - session: { id: `session_${id}`, userId: id, token: `mock_token_${id}`, expiresAt: new Date(Date.now() + 86400000).toISOString() }, |
| 217 | + session: { id: `session_${id}`, userId: id, token: `mock_token_${id}`, expiresAt: new Date(Date.now() + MOCK_SESSION_EXPIRY_MS).toISOString() }, |
216 | 218 | }, |
217 | 219 | }, |
218 | 220 | }; |
219 | 221 | } |
220 | 222 |
|
221 | 223 | // POST sign-in/email or login |
222 | 224 | if ((path === 'sign-in/email' || path === 'login') && m === 'POST') { |
223 | | - const id = `mock_${Date.now()}`; |
| 225 | + const id = `mock_${randomUUID()}`; |
224 | 226 | return { |
225 | 227 | handled: true, |
226 | 228 | response: { |
227 | 229 | status: 200, |
228 | 230 | body: { |
229 | 231 | user: { id, name: 'Mock User', email: body?.email || 'mock@test.local', emailVerified: true, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() }, |
230 | | - session: { id: `session_${id}`, userId: id, token: `mock_token_${id}`, expiresAt: new Date(Date.now() + 86400000).toISOString() }, |
| 232 | + session: { id: `session_${id}`, userId: id, token: `mock_token_${id}`, expiresAt: new Date(Date.now() + MOCK_SESSION_EXPIRY_MS).toISOString() }, |
231 | 233 | }, |
232 | 234 | }, |
233 | 235 | }; |
|
0 commit comments