There is a saveUserInfo
method that checks if there is a user with such an email, but I log in with the same account and it creates an entry in the database for me every time, although it should not.
override suspend fun saveUserInfo(user: UserResponse): Boolean = withContext(dispatcher) {
try {
val existingUser = transaction {
UserEntity.find { UserTable.emailAddress eq user.emailAddress }.singleOrNull()
}
if (existingUser == null) {
logger.debug("User does not exist, creating a new one")
transaction {
UserEntity.new {
name = user.name
emailAddress = user.emailAddress
profilePhoto = user.profilePhoto
}
}
logger.debug("User successfully created")
true
} else {
logger.debug("User already exists")
false
}
} catch (e: Exception) {
logger.error("Error in saveUserInfo: ${e.message}", e)
false
}
}
singleOrNull()
will return an element if there is exactly one, and null
otherwise. As long as you already have more than one user with the same address in your database, this code will always create more new users.
This code doesn't show how the second user got created. My guess would be a bug in a previous version.