diff --git a/backend/src/oauth/oauth.service.ts b/backend/src/oauth/oauth.service.ts index 0a374ec2..c44e53ec 100644 --- a/backend/src/oauth/oauth.service.ts +++ b/backend/src/oauth/oauth.service.ts @@ -102,9 +102,9 @@ export class OAuthService { } } - private async getAvailableUsername(email: string) { - // only remove + and - from email for now (maybe not enough) - let username = email.split("@")[0].replace(/[+-]/g, "").substring(0, 20); + private async getAvailableUsername(preferredUsername: string) { + // only remove + and - from preferred username for now (maybe not enough) + let username = preferredUsername.replace(/[+-]/g, "").substring(0, 20); while (true) { const user = await this.prisma.user.findFirst({ where: { @@ -153,7 +153,7 @@ export class OAuthService { const result = await this.auth.signUp({ email: user.email, - username: await this.getAvailableUsername(user.email), + username: await this.getAvailableUsername(user.providerUsername), password: null, }); diff --git a/backend/src/oauth/provider/genericOidc.provider.ts b/backend/src/oauth/provider/genericOidc.provider.ts index 4cff24ee..c69134dd 100644 --- a/backend/src/oauth/provider/genericOidc.provider.ts +++ b/backend/src/oauth/provider/genericOidc.provider.ts @@ -125,9 +125,9 @@ export abstract class GenericOidcProvider implements OAuthProvider { const username = claim ? idTokenData[claim] - : idTokenData.name || - idTokenData.nickname || - idTokenData.preferred_username; + : idTokenData.preferred_username || + idTokenData.name || + idTokenData.nickname; if (!username) { this.logger.error(