Skip to content

Commit

Permalink
fix redis code
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowonpaper committed Oct 17, 2024
1 parent e9ac7ae commit 69dc2d5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pages/sessions/basic-api/redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function createSession(token: string, userId: number): Promise<Sess
// TODO
}

export async function validateSessionToken(token: string): Promise<Session> {
export async function validateSessionToken(token: string): Promise<Session | null> {
// TODO
}

Expand Down Expand Up @@ -72,7 +72,7 @@ import { sha256 } from "@oslojs/crypto/sha2";

// ...

export async function createSession(token: string, userId: number): Session {
export async function createSession(token: string, userId: number): Promise<Session> {
const sessionId = encodeHexLowerCase(sha256(new TextEncoder().encode(token)));
const session: Session = {
id: sessionId,
Expand Down Expand Up @@ -108,7 +108,7 @@ import { sha256 } from "@oslojs/crypto/sha2";

// ...

export async function validateSessionToken(token: string): Promise<Session> {
export async function validateSessionToken(token: string): Promise<Session | null> {
const sessionId = encodeHexLowerCase(sha256(new TextEncoder().encode(token)));
const item = await redis.get(`session:${sessionId}`);
if (item === null) {
Expand Down Expand Up @@ -168,7 +168,7 @@ export function generateSessionToken(): string {
return token;
}

export async function createSession(token: string, userId: number): Session {
export async function createSession(token: string, userId: number): Promise<Session> {
const sessionId = encodeHexLowerCase(sha256(new TextEncoder().encode(token)));
const session: Session = {
id: sessionId,
Expand All @@ -189,7 +189,7 @@ export async function createSession(token: string, userId: number): Session {
return session;
}

export async function validateSessionToken(token: string): Promise<Session> {
export async function validateSessionToken(token: string): Promise<Session | null> {
const sessionId = encodeHexLowerCase(sha256(new TextEncoder().encode(token)));
const item = await redis.get(`session:${sessionId}`);
if (item === null) {
Expand Down

0 comments on commit 69dc2d5

Please sign in to comment.