Skip to content

Commit

Permalink
fix: link and unlink accounts (#803)
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc authored Sep 13, 2023
1 parent 106ad73 commit 8daf1d1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/main/java/io/supertokens/inmemorydb/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -2865,13 +2865,27 @@ public void makePrimaryUser_Transaction(AppIdentifier appIdentifier, Transaction
@Override
public void linkAccounts_Transaction(AppIdentifier appIdentifier, TransactionConnection con, String recipeUserId,
String primaryUserId) throws StorageQueryException {
// TODO:...
try {
Connection sqlCon = (Connection) con.getConnection();
// we do not bother returning if a row was updated here or not, cause it's happening
// in a transaction anyway.
GeneralQueries.linkAccounts_Transaction(this, sqlCon, appIdentifier, recipeUserId, primaryUserId);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

@Override
public void unlinkAccounts_Transaction(AppIdentifier appIdentifier, TransactionConnection con, String primaryUserId, String recipeUserId)
throws StorageQueryException {
// TODO:..
try {
Connection sqlCon = (Connection) con.getConnection();
// we do not bother returning if a row was updated here or not, cause it's happening
// in a transaction anyway.
GeneralQueries.unlinkAccounts_Transaction(this, sqlCon, appIdentifier, recipeUserId);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,33 @@ public static void makePrimaryUser_Transaction(Start start, Connection sqlCon, A
});
}

public static void linkAccounts_Transaction(Start start, Connection sqlCon, AppIdentifier appIdentifier,
String recipeUserId, String primaryUserId)
throws SQLException, StorageQueryException {
String QUERY = "UPDATE " + getConfig(start).getUsersTable() +
" SET is_linked_or_is_a_primary_user = true, primary_or_recipe_user_id = ? WHERE app_id = ? AND " +
"user_id = ?";
update(sqlCon, QUERY, pst -> {
pst.setString(1, primaryUserId);
pst.setString(2, appIdentifier.getAppId());
pst.setString(3, recipeUserId);
});
}

public static void unlinkAccounts_Transaction(Start start, Connection sqlCon, AppIdentifier appIdentifier,
String recipeUserId)
throws SQLException, StorageQueryException {
String QUERY = "UPDATE " + getConfig(start).getUsersTable() +
" SET is_linked_or_is_a_primary_user = false, primary_or_recipe_user_id = ? WHERE app_id = ? AND " +
"user_id = ?";

update(sqlCon, QUERY, pst -> {
pst.setString(1, recipeUserId);
pst.setString(2, appIdentifier.getAppId());
pst.setString(3, recipeUserId);
});
}

public static AuthRecipeUserInfo[] listPrimaryUsersByPhoneNumber_Transaction(Start start, Connection sqlCon,
TenantIdentifier tenantIdentifier,
String phoneNumber)
Expand Down

0 comments on commit 8daf1d1

Please sign in to comment.