mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-01 23:58:58 -04:00
fix: change sessionstate type to prevent unset values
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
f78fd69bf4
commit
229d4a4a1d
6 changed files with 26 additions and 27 deletions
|
@ -36,7 +36,7 @@ describe('SessionService', () => {
|
|||
jest.resetModules();
|
||||
jest.restoreAllMocks();
|
||||
const mockedExistingSession = Mock.of<SessionState>({
|
||||
user: mockUsername,
|
||||
username: mockUsername,
|
||||
});
|
||||
mockedTypeormStore = Mock.of<TypeormStore>({
|
||||
connect: jest.fn(() => mockedTypeormStore),
|
||||
|
|
|
@ -22,7 +22,7 @@ import { HEDGEDOC_SESSION } from '../utils/session';
|
|||
|
||||
export interface SessionState {
|
||||
cookie: unknown;
|
||||
user: string;
|
||||
username?: string;
|
||||
authProvider: string;
|
||||
}
|
||||
|
||||
|
@ -58,10 +58,10 @@ export class SessionService {
|
|||
* @param sessionId The session id for which the owning user should be found
|
||||
* @return A Promise that either resolves with the username or rejects with an error
|
||||
*/
|
||||
fetchUsernameForSessionId(sessionId: string): Promise<string> {
|
||||
fetchUsernameForSessionId(sessionId: string): Promise<string | undefined> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.typeormStore.get(sessionId, (error?: Error, result?: SessionState) =>
|
||||
error || !result ? reject(error) : resolve(result.user),
|
||||
error || !result ? reject(error) : resolve(result.username),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue