Skip to content

Commit 9e45cb0

Browse files
AlexTugarevroboquat
authored andcommitted
[server] fix persist of DBOAuthAuthCodeEntry
1 parent cd144de commit 9e45cb0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

components/gitpod-db/src/typeorm/auth-code-repository-db.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export class AuthCodeRepositoryDB implements OAuthAuthCodeRepository {
4545
return authCode;
4646
}
4747
public issueAuthCode(client: OAuthClient, user: OAuthUser | undefined, scopes: OAuthScope[]): OAuthAuthCode {
48+
if (!user) {
49+
// this would otherwise break persisting of an DBOAuthAuthCodeEntry down below
50+
throw new Error("Cannot issue auth code for unknown user.");
51+
}
4852
const code = crypto.randomBytes(30).toString("hex");
4953
// NOTE: caller (@jmondi/oauth2-server) is responsible for adding the remaining items, PKCE params, redirect URL, etc
5054
return {
@@ -56,10 +60,11 @@ export class AuthCodeRepositoryDB implements OAuthAuthCodeRepository {
5660
};
5761
}
5862
public async persist(authCode: DBOAuthAuthCodeEntry): Promise<void> {
63+
// authCode is created in issueAuthCode 👆
5964
try {
6065
const authCodeRepo = await this.getOauthAuthCodeRepo();
6166
authCode.id = uuidv4();
62-
authCodeRepo.save(authCode);
67+
await authCodeRepo.save(authCode);
6368
} catch (error) {
6469
console.error("Error while persisting an DBOAuthAuthCodeEntry.", error, { error });
6570
}

0 commit comments

Comments
 (0)