Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: link and unlink accounts #803

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading