mirror of
https://github.com/stonith404/pingvin-share.git
synced 2025-01-15 01:14:27 -05:00
fix(oauth): provider username is ignored when signing up using OAuth (#511)
* 🐛 Bug Report: Provider username is ignored when signing up using OAuth Fixes #505 Signed-off-by: Marvin A. Ruder <signed@mruder.dev> * Implement fallback logic for username conflicts * Reprioritize claims for OIDC provider username Signed-off-by: Marvin A. Ruder <signed@mruder.dev> --------- Signed-off-by: Marvin A. Ruder <signed@mruder.dev>
This commit is contained in:
parent
2dac38560b
commit
31366d961f
2 changed files with 7 additions and 7 deletions
|
@ -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,
|
||||
});
|
||||
|
||||
|
|
|
@ -125,9 +125,9 @@ export abstract class GenericOidcProvider implements OAuthProvider<OidcToken> {
|
|||
|
||||
const username = claim
|
||||
? idTokenData[claim]
|
||||
: idTokenData.name ||
|
||||
idTokenData.nickname ||
|
||||
idTokenData.preferred_username;
|
||||
: idTokenData.preferred_username ||
|
||||
idTokenData.name ||
|
||||
idTokenData.nickname;
|
||||
|
||||
if (!username) {
|
||||
this.logger.error(
|
||||
|
|
Loading…
Add table
Reference in a new issue