Skip to content

Commit

Permalink
fix: remove UserInfo class (#772)
Browse files Browse the repository at this point in the history
* fix: remove UserInfo class

* fix: remove getRecipeId

* fix: uncomment test
  • Loading branch information
sattvikc authored Aug 26, 2023
1 parent 0a79d5a commit 3ce68da
Show file tree
Hide file tree
Showing 45 changed files with 251 additions and 331 deletions.
13 changes: 6 additions & 7 deletions src/main/java/io/supertokens/emailpassword/EmailPassword.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import io.supertokens.pluginInterface.authRecipe.LoginMethod;
import io.supertokens.pluginInterface.authRecipe.sqlStorage.AuthRecipeSQLStorage;
import io.supertokens.pluginInterface.emailpassword.PasswordResetTokenInfo;
import io.supertokens.pluginInterface.emailpassword.UserInfo;
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateEmailException;
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicatePasswordResetTokenException;
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateUserIdException;
Expand Down Expand Up @@ -83,7 +82,7 @@ private static long getPasswordResetTokenLifetime(TenantIdentifier tenantIdentif
}

@TestOnly
public static UserInfo signUp(Main main, @Nonnull String email, @Nonnull String password)
public static AuthRecipeUserInfo signUp(Main main, @Nonnull String email, @Nonnull String password)
throws DuplicateEmailException, StorageQueryException {
try {
Storage storage = StorageLayer.getStorage(main);
Expand All @@ -94,7 +93,7 @@ public static UserInfo signUp(Main main, @Nonnull String email, @Nonnull String
}
}

public static UserInfo signUp(TenantIdentifierWithStorage tenantIdentifierWithStorage, Main main,
public static AuthRecipeUserInfo signUp(TenantIdentifierWithStorage tenantIdentifierWithStorage, Main main,
@Nonnull String email, @Nonnull String password)
throws DuplicateEmailException, StorageQueryException, TenantOrAppNotFoundException,
BadPermissionException {
Expand Down Expand Up @@ -167,7 +166,7 @@ public static ImportUserResponse importUserWithPasswordHash(TenantIdentifierWith
EmailPasswordSQLStorage storage = tenantIdentifierWithStorage.getEmailPasswordStorage();

try {
UserInfo userInfo = storage.signUp(tenantIdentifierWithStorage, userId, email, passwordHash,
AuthRecipeUserInfo userInfo = storage.signUp(tenantIdentifierWithStorage, userId, email, passwordHash,
timeJoined);
return new ImportUserResponse(false, userInfo);
} catch (DuplicateUserIdException e) {
Expand Down Expand Up @@ -663,7 +662,7 @@ public static void updateUsersEmailOrPassword(AppIdentifierWithStorage appIdenti

@Deprecated
@TestOnly
public static UserInfo getUserUsingId(Main main, String userId)
public static AuthRecipeUserInfo getUserUsingId(Main main, String userId)
throws StorageQueryException {
try {
Storage storage = StorageLayer.getStorage(main);
Expand All @@ -674,7 +673,7 @@ public static UserInfo getUserUsingId(Main main, String userId)
}

@Deprecated
public static UserInfo getUserUsingId(AppIdentifierWithStorage appIdentifierWithStorage, String userId)
public static AuthRecipeUserInfo getUserUsingId(AppIdentifierWithStorage appIdentifierWithStorage, String userId)
throws StorageQueryException, TenantOrAppNotFoundException {
AuthRecipeUserInfo result = appIdentifierWithStorage.getAuthRecipeStorage()
.getPrimaryUserById(appIdentifierWithStorage, userId);
Expand All @@ -683,7 +682,7 @@ public static UserInfo getUserUsingId(AppIdentifierWithStorage appIdentifierWith
}
for (LoginMethod lM : result.loginMethods) {
if (lM.getSupertokensUserId().equals(userId)) {
return new UserInfo(lM.getSupertokensUserId(), result.isPrimaryUser, lM);
return AuthRecipeUserInfo.create(lM.getSupertokensUserId(), result.isPrimaryUser, lM);
}
}
return null;
Expand Down

This file was deleted.

7 changes: 3 additions & 4 deletions src/main/java/io/supertokens/inmemorydb/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import io.supertokens.pluginInterface.dashboard.exceptions.UserIdNotFoundException;
import io.supertokens.pluginInterface.dashboard.sqlStorage.DashboardSQLStorage;
import io.supertokens.pluginInterface.emailpassword.PasswordResetTokenInfo;
import io.supertokens.pluginInterface.emailpassword.UserInfo;
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateEmailException;
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicatePasswordResetTokenException;
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateUserIdException;
Expand Down Expand Up @@ -725,7 +724,7 @@ public String[] getProtectedConfigsFromSuperTokensSaaSUsers() {
}

@Override
public UserInfo signUp(TenantIdentifier tenantIdentifier, String id, String email, String passwordHash,
public AuthRecipeUserInfo signUp(TenantIdentifier tenantIdentifier, String id, String email, String passwordHash,
long timeJoined)
throws StorageQueryException, DuplicateUserIdException, DuplicateEmailException,
TenantOrAppNotFoundException {
Expand Down Expand Up @@ -1074,7 +1073,7 @@ public void deleteThirdPartyUser_Transaction(TransactionConnection con, AppIdent
}

@Override
public io.supertokens.pluginInterface.thirdparty.UserInfo signUp(
public AuthRecipeUserInfo signUp(
TenantIdentifier tenantIdentifier, String id, String email,
LoginMethod.ThirdParty thirdParty, long timeJoined)
throws StorageQueryException, io.supertokens.pluginInterface.thirdparty.exception.DuplicateUserIdException,
Expand Down Expand Up @@ -1618,7 +1617,7 @@ public void createCode(TenantIdentifier tenantIdentifier, PasswordlessCode code)
}

@Override
public io.supertokens.pluginInterface.passwordless.UserInfo createUser(TenantIdentifier tenantIdentifier,
public AuthRecipeUserInfo createUser(TenantIdentifier tenantIdentifier,
String id,
@javax.annotation.Nullable String email,
@javax.annotation.Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import io.supertokens.inmemorydb.Utils;
import io.supertokens.inmemorydb.config.Config;
import io.supertokens.pluginInterface.RowMapper;
import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo;
import io.supertokens.pluginInterface.authRecipe.LoginMethod;
import io.supertokens.pluginInterface.emailpassword.PasswordResetTokenInfo;
import io.supertokens.pluginInterface.emailpassword.UserInfo;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
Expand Down Expand Up @@ -228,8 +228,8 @@ public static void addPasswordResetToken(Start start, AppIdentifier appIdentifie
});
}

public static UserInfo signUp(Start start, TenantIdentifier tenantIdentifier, String userId, String email,
String passwordHash, long timeJoined)
public static AuthRecipeUserInfo signUp(Start start, TenantIdentifier tenantIdentifier, String userId, String email,
String passwordHash, long timeJoined)
throws StorageQueryException, StorageTransactionLogicException {
return start.startTransaction(con -> {
Connection sqlCon = (Connection) con.getConnection();
Expand Down Expand Up @@ -287,7 +287,7 @@ public static UserInfo signUp(Start start, TenantIdentifier tenantIdentifier, St
fillUserInfoWithTenantIds_transaction(start, sqlCon, tenantIdentifier.toAppIdentifier(), userInfo);
fillUserInfoWithVerified_transaction(start, sqlCon, tenantIdentifier.toAppIdentifier(), userInfo);
sqlCon.commit();
return new UserInfo(userId, false, userInfo.toLoginMethod());
return AuthRecipeUserInfo.create(userId, false, userInfo.toLoginMethod());
} catch (SQLException throwables) {
throw new StorageTransactionLogicException(throwables);
}
Expand Down Expand Up @@ -511,7 +511,7 @@ private static List<UserInfoPartial> fillUserInfoWithTenantIds_transaction(Start
Map<String, List<String>> tenantIdsForUserIds = GeneralQueries.getTenantIdsForUserIds_transaction(start, sqlCon,
appIdentifier,
userIds);
List<UserInfo> result = new ArrayList<>();
List<AuthRecipeUserInfo> result = new ArrayList<>();
for (UserInfoPartial userInfo : userInfos) {
userInfo.tenantIds = tenantIdsForUserIds.get(userInfo.id).toArray(new String[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import io.supertokens.inmemorydb.Utils;
import io.supertokens.inmemorydb.config.Config;
import io.supertokens.pluginInterface.RowMapper;
import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo;
import io.supertokens.pluginInterface.authRecipe.LoginMethod;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.passwordless.PasswordlessCode;
import io.supertokens.pluginInterface.passwordless.PasswordlessDevice;
import io.supertokens.pluginInterface.passwordless.UserInfo;
import io.supertokens.pluginInterface.sqlStorage.SQLStorage.TransactionIsolationLevel;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -365,8 +365,8 @@ public static void deleteCode_Transaction(Start start, Connection con, TenantIde
});
}

public static UserInfo createUser(Start start, TenantIdentifier tenantIdentifier, String id, @Nullable String email,
@Nullable String phoneNumber, long timeJoined)
public static AuthRecipeUserInfo createUser(Start start, TenantIdentifier tenantIdentifier, String id, @Nullable String email,
@Nullable String phoneNumber, long timeJoined)
throws StorageTransactionLogicException, StorageQueryException {
return start.startTransaction(con -> {
Connection sqlCon = (Connection) con.getConnection();
Expand Down Expand Up @@ -424,7 +424,7 @@ public static UserInfo createUser(Start start, TenantIdentifier tenantIdentifier
fillUserInfoWithTenantIds_transaction(start, sqlCon, tenantIdentifier.toAppIdentifier(), userInfo);
fillUserInfoWithVerified_transaction(start, sqlCon, tenantIdentifier.toAppIdentifier(), userInfo);
sqlCon.commit();
return new UserInfo(id, false,
return AuthRecipeUserInfo.create(id, false,
userInfo.toLoginMethod());
} catch (SQLException throwables) {
throw new StorageTransactionLogicException(throwables);
Expand Down Expand Up @@ -931,7 +931,7 @@ private static List<UserInfoPartial> fillUserInfoWithTenantIds_transaction(Start
Map<String, List<String>> tenantIdsForUserIds = GeneralQueries.getTenantIdsForUserIds_transaction(start, sqlCon,
appIdentifier,
userIds);
List<UserInfo> result = new ArrayList<>();
List<AuthRecipeUserInfo> result = new ArrayList<>();
for (UserInfoPartial userInfo : userInfos) {
userInfo.tenantIds = tenantIdsForUserIds.get(userInfo.id).toArray(new String[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import io.supertokens.inmemorydb.Utils;
import io.supertokens.inmemorydb.config.Config;
import io.supertokens.pluginInterface.RowMapper;
import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo;
import io.supertokens.pluginInterface.authRecipe.LoginMethod;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.thirdparty.UserInfo;

import java.sql.Connection;
import java.sql.ResultSet;
Expand Down Expand Up @@ -83,8 +83,8 @@ static String getQueryToCreateThirdPartyUserToTenantTable(Start start) {
// @formatter:on
}

public static UserInfo signUp(Start start, TenantIdentifier tenantIdentifier, String id, String email,
LoginMethod.ThirdParty thirdParty, long timeJoined)
public static AuthRecipeUserInfo signUp(Start start, TenantIdentifier tenantIdentifier, String id, String email,
LoginMethod.ThirdParty thirdParty, long timeJoined)
throws StorageQueryException, StorageTransactionLogicException {
return start.startTransaction(con -> {
Connection sqlCon = (Connection) con.getConnection();
Expand Down Expand Up @@ -144,7 +144,7 @@ public static UserInfo signUp(Start start, TenantIdentifier tenantIdentifier, St
fillUserInfoWithTenantIds_transaction(start, sqlCon, tenantIdentifier.toAppIdentifier(), userInfo);
fillUserInfoWithVerified_transaction(start, sqlCon, tenantIdentifier.toAppIdentifier(), userInfo);
sqlCon.commit();
return new UserInfo(id, false, userInfo.toLoginMethod());
return AuthRecipeUserInfo.create(id, false, userInfo.toLoginMethod());

} catch (SQLException throwables) {
throw new StorageTransactionLogicException(throwables);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/io/supertokens/passwordless/Passwordless.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.pluginInterface.passwordless.PasswordlessCode;
import io.supertokens.pluginInterface.passwordless.PasswordlessDevice;
import io.supertokens.pluginInterface.passwordless.UserInfo;
import io.supertokens.pluginInterface.passwordless.exception.*;
import io.supertokens.pluginInterface.passwordless.sqlStorage.PasswordlessSQLStorage;
import io.supertokens.storageLayer.StorageLayer;
Expand Down Expand Up @@ -529,15 +528,15 @@ public static void removeCodesByPhoneNumber(TenantIdentifierWithStorage tenantId

@TestOnly
@Deprecated
public static UserInfo getUserById(Main main, String userId)
public static AuthRecipeUserInfo getUserById(Main main, String userId)
throws StorageQueryException {
Storage storage = StorageLayer.getStorage(main);
return getUserById(
new AppIdentifierWithStorage(null, null, storage), userId);
}

@Deprecated
public static UserInfo getUserById(AppIdentifierWithStorage appIdentifierWithStorage, String userId)
public static AuthRecipeUserInfo getUserById(AppIdentifierWithStorage appIdentifierWithStorage, String userId)
throws StorageQueryException {
AuthRecipeUserInfo result = appIdentifierWithStorage.getAuthRecipeStorage()
.getPrimaryUserById(appIdentifierWithStorage, userId);
Expand All @@ -546,7 +545,7 @@ public static UserInfo getUserById(AppIdentifierWithStorage appIdentifierWithSto
}
for (LoginMethod lM : result.loginMethods) {
if (lM.getSupertokensUserId().equals(userId)) {
return new io.supertokens.pluginInterface.passwordless.UserInfo(lM.getSupertokensUserId(), result.isPrimaryUser,
return AuthRecipeUserInfo.create(lM.getSupertokensUserId(), result.isPrimaryUser,
lM);
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/io/supertokens/thirdparty/ThirdParty.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException;
import io.supertokens.pluginInterface.multitenancy.*;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.pluginInterface.thirdparty.UserInfo;
import io.supertokens.pluginInterface.thirdparty.exception.DuplicateThirdPartyUserException;
import io.supertokens.pluginInterface.thirdparty.exception.DuplicateUserIdException;
import io.supertokens.pluginInterface.thirdparty.sqlStorage.ThirdPartySQLStorage;
Expand Down Expand Up @@ -158,7 +157,7 @@ private static SignInUpResponse signInUpHelper(TenantIdentifierWithStorage tenan
long timeJoined = System.currentTimeMillis();

try {
UserInfo createdUser = storage.signUp(tenantIdentifierWithStorage, userId, email,
AuthRecipeUserInfo createdUser = storage.signUp(tenantIdentifierWithStorage, userId, email,
new LoginMethod.ThirdParty(thirdPartyId, thirdPartyUserId), timeJoined);

return new SignInUpResponse(true, createdUser);
Expand Down Expand Up @@ -249,7 +248,7 @@ private static SignInUpResponse signInUpHelper(TenantIdentifierWithStorage tenan
}

@Deprecated
public static UserInfo getUser(AppIdentifierWithStorage appIdentifierWithStorage, String userId)
public static AuthRecipeUserInfo getUser(AppIdentifierWithStorage appIdentifierWithStorage, String userId)
throws StorageQueryException {
AuthRecipeUserInfo result = appIdentifierWithStorage.getAuthRecipeStorage()
.getPrimaryUserById(appIdentifierWithStorage, userId);
Expand All @@ -258,7 +257,7 @@ public static UserInfo getUser(AppIdentifierWithStorage appIdentifierWithStorage
}
for (LoginMethod lM : result.loginMethods) {
if (lM.getSupertokensUserId().equals(userId)) {
return new io.supertokens.pluginInterface.thirdparty.UserInfo(lM.getSupertokensUserId(), result.isPrimaryUser,
return AuthRecipeUserInfo.create(lM.getSupertokensUserId(), result.isPrimaryUser,
lM);
}
}
Expand All @@ -267,7 +266,7 @@ public static UserInfo getUser(AppIdentifierWithStorage appIdentifierWithStorage

@Deprecated
@TestOnly
public static UserInfo getUser(Main main, String userId) throws StorageQueryException {
public static AuthRecipeUserInfo getUser(Main main, String userId) throws StorageQueryException {
Storage storage = StorageLayer.getStorage(main);
return getUser(new AppIdentifierWithStorage(null, null, storage), userId);
}
Expand Down
Loading

0 comments on commit 3ce68da

Please sign in to comment.