Skip to content

Commit

Permalink
Fix typesafety in Env declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
Brayden committed Oct 23, 2024
1 parent bcb7322 commit 0e9ef9e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion templates/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { createResponse } from "./utils";

const DURABLE_OBJECT_ID = 'sql-durable-object';

export default class AuthEntrypoint extends WorkerEntrypoint {
interface Env {
DATABASE_DURABLE_OBJECT: DurableObjectNamespace;
}

export default class AuthEntrypoint extends WorkerEntrypoint<Env> {
private stub: any;

// Currently, entrypoints without a named handler are not supported
Expand Down Expand Up @@ -44,4 +48,19 @@ export default class AuthEntrypoint extends WorkerEntrypoint {
success: true,
}), undefined, 200);
}

/**
* Checks if a session is valid by checking if the session token exists and is not deleted
* @param sessionToken
* @returns
*/
async isSessionValid(sessionToken: string) {
let result = await this.stub.executeExternalQuery(
`SELECT * FROM auth_sessions
WHERE session_token = ?
AND deleted_at IS NULL`,
[sessionToken]
);
return result.result.length > 0;
}
}

0 comments on commit 0e9ef9e

Please sign in to comment.