Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix: PR bugs and login by alias

mertmit82998da4b737
diff --git a/packages/nocodb/src/models/User.ts b/packages/nocodb/src/models/User.ts
index f1b12372a0..91b2323150 100644
--- a/packages/nocodb/src/models/User.ts
+++ b/packages/nocodb/src/models/User.ts
@@ -141,6 +141,15 @@ export default class User implements UserType {
if (targetUser && targetUser.id !== id) {
NcError.badRequest('email is in use');
}
+
+ // check if a user with the same canonical email already exists
+ const canonicalUser = await this.getByCanonicalEmail(
+ updateObj.email,
+ ncMeta,
+ );
+ if (canonicalUser && canonicalUser.id !== id) {
+ NcError.badRequest('email is in use');
+ }
} else {
// set email prop to avoid generation of invalid cache key
updateObj.email = (await this.get(id, ncMeta))?.email?.toLowerCase();
@@ -470,6 +479,12 @@ export default class User implements UserType {
// clear all user related cache
await NocoCache.del('root', `${CacheScope.USER}:${userId}`);
await NocoCache.del('root', `${CacheScope.USER}:${user.email}`);
+ if (user.email) {
+ await NocoCache.del(
+ 'root',
+ `${CacheScope.USER}:canonical:${normalizeEmail(user.email)}`,
+ );
+ }
}
public static async signUserImage(
diff --git a/packages/nocodb/src/modules/auth/auth.service.ts b/packages/nocodb/src/modules/auth/auth.service.ts
index bfd80f8a08..d38ef3bfb5 100644
--- a/packages/nocodb/src/modules/auth/auth.service.ts
+++ b/packages/nocodb/src/modules/auth/auth.service.ts
@@ -2,8 +2,6 @@ import { promisify } from 'util';
import { OrgUserRoles } from 'nocodb-sdk';
import { Injectable } from '@nestjs/common';
import * as bcrypt from 'bcryptjs';
-
-import { v4 as uuidv4 } from 'uuid';
import Noco from '~/Noco';
import { genJwt } from '~/services/users/helpers';
import { UsersService } from '~/services/users/users.service';
@@ -50,33 +48,6 @@ export class AuthService {
};
}
- async signup(createUserDto: CreateUserDto) {
- const { email: _email, firstname, lastname } = createUserDto as any;
-
- let { password } = createUserDto;
-
- const email = _email.toLowerCase();
-
- let user = await this.usersService.findOne(email);
-
- const salt = await promisify(bcrypt.genSalt)(10);
- password = await promisify(bcrypt.hash)(password, salt);
- const email_verification_token = uuidv4();
-
- if (!user) {
- await this.registerNewUserIfAllowed({
- firstname,
- lastname,
- email,
- salt,
- password,
- email_verification_token,
- });
- }
- user = await this.usersService.findOne(email);
- return await this.login(user);
- }
-
async registerNewUserIfAllowed(
{
firstname,
diff --git a/packages/nocodb/src/services/users/users.service.ts b/packages/nocodb/src/services/users/users.service.ts
index 3e193738ce..10b3c68b4d 100644
--- a/packages/nocodb/src/services/users/users.service.ts
+++ b/packages/nocodb/src/services/users/users.service.ts
@@ -53,11 +53,7 @@ export class UsersService {
}
async findOne(_email: string) {
- // Try canonical lookup first (handles alias variants),
- // then fall back to exact email match for backward compat.
- const user =
- (await User.getByCanonicalEmail(_email)) ||
- (await User.getByEmail(_email));
+ const user = await User.getByEmail(_email);
await PresignedUrl.signMetaIconImage(user);