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: password reset changes #804

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
2 changes: 1 addition & 1 deletion src/main/java/io/supertokens/inmemorydb/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ public void addPasswordResetToken(AppIdentifier appIdentifier, PasswordResetToke
throws StorageQueryException, UnknownUserIdException, DuplicatePasswordResetTokenException {
try {
EmailPasswordQueries.addPasswordResetToken(this, appIdentifier, passwordResetTokenInfo.userId,
passwordResetTokenInfo.token, passwordResetTokenInfo.tokenExpiry);
passwordResetTokenInfo.token, passwordResetTokenInfo.tokenExpiry, passwordResetTokenInfo.email);
} catch (SQLException e) {
if (e instanceof SQLiteException) {
String serverMessage = e.getMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static String getQueryToCreatePasswordResetTokensTable(Start start) {
+ "token VARCHAR(128) NOT NULL UNIQUE,"
+ "token_expiry BIGINT UNSIGNED NOT NULL,"
+ "PRIMARY KEY (app_id, user_id, token),"
+ "FOREIGN KEY (app_id, user_id) REFERENCES " + Config.getConfig(start).getEmailPasswordUsersTable()
+ "FOREIGN KEY (app_id, user_id) REFERENCES " + Config.getConfig(start).getAppIdToUserIdTable()
+ " (app_id, user_id) ON DELETE CASCADE ON UPDATE CASCADE"
+ ");";
}
Expand Down Expand Up @@ -215,17 +215,30 @@ public static PasswordResetTokenInfo getPasswordResetTokenInfo(Start start, AppI
}

public static void addPasswordResetToken(Start start, AppIdentifier appIdentifier, String userId, String tokenHash,
long expiry)
long expiry, String email)
throws SQLException, StorageQueryException {
String QUERY = "INSERT INTO " + getConfig(start).getPasswordResetTokensTable()
+ "(app_id, user_id, token, token_expiry)" + " VALUES(?, ?, ?, ?)";
if (email != null) {
String QUERY = "INSERT INTO " + getConfig(start).getPasswordResetTokensTable()
+ "(app_id, user_id, token, token_expiry, email)" + " VALUES(?, ?, ?, ?, ?)";

update(start, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
pst.setString(3, tokenHash);
pst.setLong(4, expiry);
});
update(start, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
pst.setString(3, tokenHash);
pst.setLong(4, expiry);
pst.setString(5, email);
});
} else {
String QUERY = "INSERT INTO " + getConfig(start).getPasswordResetTokensTable()
+ "(app_id, user_id, token, token_expiry)" + " VALUES(?, ?, ?, ?)";

update(start, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
pst.setString(3, tokenHash);
pst.setLong(4, expiry);
});
}
}

public static AuthRecipeUserInfo signUp(Start start, TenantIdentifier tenantIdentifier, String userId, String email,
Expand Down Expand Up @@ -322,6 +335,15 @@ public static void deleteUser_Transaction(Connection sqlCon, Start start, AppIde
pst.setString(2, userId);
});
}

{
String QUERY = "DELETE FROM " + getConfig(start).getPasswordResetTokensTable()
+ " WHERE app_id = ? AND user_id = ?";
update(sqlCon, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
pst.setString(2, userId);
});
}
}
}

Expand Down
Loading