@@ -28,9 +28,9 @@ The secret hash is stored as a raw binary value. You can hex- or base64-encode i
2828
2929```
3030CREATE TABLE session (
31- id TEXT NOT NULL PRIMARY KEY,
32- secret_hash BLOB NOT NULL, -- blob is a SQLite data type for raw binary
33- created_at INTEGER NOT NULL -- unix time (seconds)
31+ id TEXT NOT NULL PRIMARY KEY,
32+ secret_hash BLOB NOT NULL, -- blob is a SQLite data type for raw binary
33+ created_at INTEGER NOT NULL -- unix time (seconds)
3434) STRICT;
3535```
3636
@@ -47,7 +47,7 @@ Since these strings will be used as secrets as well, it's crucial to use a crypt
4747``` ts
4848function generateSecureRandomString(): string {
4949 // Human readable alphabet (a-z, 0-9 without l, o, 0, 1 to avoid confusion)
50- const alphabet = " abcdefghijklmnpqrstuvwxyz23456789 " ;
50+ const alphabet = " abcdefghijkmnpqrstuvwxyz23456789 " ;
5151
5252 // Generate 24 bytes = 192 bits of entropy.
5353 // We're only going to use 5 bits per byte so the total entropy will be 192 * 5 / 8 = 120 bits
@@ -56,7 +56,7 @@ function generateSecureRandomString(): string {
5656
5757 let id = " " ;
5858 for (let i = 0 ; i < bytes .length ; i ++ ) {
59- // >> 3 s "removes" the right-most 3 bits of the byte
59+ // >> 3 "removes" the right-most 3 bits of the byte
6060 id += alphabet [bytes [i ] >> 3 ];
6161 }
6262 return id ;
@@ -125,13 +125,16 @@ async function createSession(dbPool: DBPool): Promise<SessionWithToken> {
125125
126126async function validateSessionToken(dbPool : DBPool , token : string ): Promise <Session | null > {
127127 const tokenParts = token .split (" ." );
128- if (tokenParts .length != 2 ) {
128+ if (tokenParts .length !== 2 ) {
129129 return null ;
130130 }
131131 const sessionId = tokenParts [0 ];
132132 const sessionSecret = tokenParts [1 ];
133133
134134 const session = await getSession (dbPool , sessionId );
135+ if (! session ) {
136+ return null ;
137+ }
135138
136139 const tokenSecretHash = await hashSecret (sessionSecret );
137140 const validSecret = constantTimeEqual (tokenSecretHash , session .secretHash );
0 commit comments