-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use in-memory token store when developing locally (#273)
* Use in-memory token store when developing locally Removes the need for a local Redis container * Remove docker-compose dependency * Default to disabled when running locally * Rename to InMemoryTokenStore + explicitly create session MemoryStore
- Loading branch information
1 parent
ca2cfee
commit 3949b48
Showing
17 changed files
with
73 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import TokenStore from './inMemoryTokenStore' | ||
|
||
describe('inMemoryTokenStore', () => { | ||
let tokenStore: TokenStore | ||
|
||
beforeEach(() => { | ||
tokenStore = new TokenStore() | ||
}) | ||
|
||
it('Can store and retrieve token', async () => { | ||
await tokenStore.setToken('user-1', 'token-1', 10) | ||
expect(await tokenStore.getToken('user-1')).toBe('token-1') | ||
}) | ||
|
||
it('Expires token', async () => { | ||
await tokenStore.setToken('user-2', 'token-2', -1) | ||
expect(await tokenStore.getToken('user-2')).toBe(null) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import TokenStore from './tokenStore' | ||
|
||
export default class InMemoryTokenStore implements TokenStore { | ||
map = new Map<string, { token: string; expiry: Date }>() | ||
|
||
public async setToken(key: string, token: string, durationSeconds: number): Promise<void> { | ||
this.map.set(key, { token, expiry: new Date(Date.now() + durationSeconds * 1000) }) | ||
return Promise.resolve() | ||
} | ||
|
||
public async getToken(key: string): Promise<string> { | ||
if (!this.map.has(key) || this.map.get(key).expiry.getTime() < Date.now()) { | ||
return Promise.resolve(null) | ||
} | ||
return Promise.resolve(this.map.get(key).token) | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
server/data/tokenStore.test.ts → ...r/data/tokenStore/redisTokenStore.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
server/data/tokenStore.ts → server/data/tokenStore/redisTokenStore.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default interface TokenStore { | ||
setToken(key: string, token: string, durationSeconds: number): Promise<void> | ||
getToken(key: string): Promise<string> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters