* Get session data from Redis * @param sessionId The session ID * @returns Session data or null if not found
(sessionId: string)
| 24 | * @returns Session data or null if not found |
| 25 | */ |
| 26 | async getSession(sessionId: string): Promise<UserSession | null> { |
| 27 | const data = await redis.get(`session:${sessionId}`); |
| 28 | if (!data) return null; |
| 29 | |
| 30 | try { |
| 31 | const session = JSON.parse(data) as UserSession; |
| 32 | |
| 33 | // Convert date strings back to Date objects |
| 34 | if (session.expiresAt) { |
| 35 | session.expiresAt = new Date(session.expiresAt); |
| 36 | } |
| 37 | if (session.createdAt) { |
| 38 | session.createdAt = new Date(session.createdAt); |
| 39 | } |
| 40 | |
| 41 | return session; |
| 42 | } catch (error) { |
| 43 | console.error("Error parsing session data:", error); |
| 44 | return null; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Remove a session from Redis |
no outgoing calls
no test coverage detected