Skip to content

Commit 0e9ef9e

Browse files
committed
Fix typesafety in Env declaration
1 parent bcb7322 commit 0e9ef9e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

templates/auth/src/index.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { createResponse } from "./utils";
44

55
const DURABLE_OBJECT_ID = 'sql-durable-object';
66

7-
export default class AuthEntrypoint extends WorkerEntrypoint {
7+
interface Env {
8+
DATABASE_DURABLE_OBJECT: DurableObjectNamespace;
9+
}
10+
11+
export default class AuthEntrypoint extends WorkerEntrypoint<Env> {
812
private stub: any;
913

1014
// Currently, entrypoints without a named handler are not supported
@@ -44,4 +48,19 @@ export default class AuthEntrypoint extends WorkerEntrypoint {
4448
success: true,
4549
}), undefined, 200);
4650
}
51+
52+
/**
53+
* Checks if a session is valid by checking if the session token exists and is not deleted
54+
* @param sessionToken
55+
* @returns
56+
*/
57+
async isSessionValid(sessionToken: string) {
58+
let result = await this.stub.executeExternalQuery(
59+
`SELECT * FROM auth_sessions
60+
WHERE session_token = ?
61+
AND deleted_at IS NULL`,
62+
[sessionToken]
63+
);
64+
return result.result.length > 0;
65+
}
4766
}

0 commit comments

Comments
 (0)