Skip to content

Commit

Permalink
feat: account linking (#742)
Browse files Browse the repository at this point in the history
* table schema changes

* changes to user count API

* small change

* implements changes to auth queries to fetch tenant ids and verified status

* fixes a few bugs

* more changes

* fixes query

* fixes tests

* all test fixes

* removes a few unnecessary functions

* uses new interface to fetch user based on id

* adds stub for new function

* removes use of unnecessary function

* changes based on interface

* adds function for list user by phone number

* optimises a query

* more intefrace function

* removes unused interface func

* adds migration script to changelog

* small changes

* refactor

* removes unneeded functions

* adds user get API

* get users by account info API

* adds new func signature

* creates new indices

* adds impl for creating a primary user

* implements one of the functions

* adds more query impls

* fixes small issue

* starts working on account linking tests

* adds a few tests

* adds more tests

* more tests

* adds link account function

* removes unneeded index

* adds test only func and also adds feature flag check

* more changes

* adds one account linking test

* adds more tests

* more tests

* more tests

* more tests

* more tests

* mods delete function

* small file change

* delete function change

* fixes a bug

* adds more tests

* adds unliking accounts function

* refactors for link accounts function

* more refactor

* adds API for can create primary user

* adds create primary user API, except for converting tuser obj to json

* fixes older APIs

* fixes tests

* removes unneeded file

* starts working on can link accounts api

* adds more tests

* more tests

* new tests

* adds tests for linking accounts API

* adds unlink accounts API

* adds more tests

* more changes

* changes for password reset flow

* more tests

* more tests

* implements consumeCode function

* adds API to consume reset password code

* adds more tests

* adds more tests

* removes unnecessary comment

* adds more tests

* updates to updatemeailorpassword function

* adds more tests

* updates tp sign in to check for email update allowance

* more tests

* adds more tests

* fixes a bug

* adds recipe user id in session

* adds session changes to changelog

* changes claim ro rsub

* changes API spec

* changes API spec

* changes to passwordless recipe update user

* renames variable

* fix: account linking tests (#764)

* fix: tests

* fix: tests

* fix: tests

* fix: tests

* fix: pr comments

* fix: pr comments

* fix: user pagination changes (#766)

* fix: user pagination changes

* fix: user pagination changes

* fix: remove extra wrapper around user objects in users list

* feat: update latest access token version

* fix: user pagination tests (#768)

* fix: user pagination tests

* fix: user pagination tests

* fix: recipeUserId in sign in/up related APIs (#769)

* fix: recipeUserId in sign in/up related APIs

* fix: phone and email case

* fix: pr comments

* fix: test with external user id

* fix: pr comments

* fix: pr comments

* fix: pr comments

* fix: pr comments

* fix: External userid (#770)

* fix: recipeUserId in sign in/up related APIs

* fix: phone and email case

* fix: pr comments

* fix: test with external user id

* fix: pr comments

* fix: pr comments

* fix: pr comments

* fix: pr comments

* fix: external userid

* fix: tests

* fix: user object in link accounts api (#771)

* fix: link accounts api

* fix: minor fix

* fix: tests

* fix: remove UserInfo class (#772)

* fix: remove UserInfo class

* fix: remove getRecipeId

* fix: uncomment test

* fix: emailverified in tp & pless (#774)

* fix: email verification in thirdparty and pless

* fix: email verification

* fix: more test for passwordless

* fix: thirdparty and tests

* fix: remove active user of recipe user when linked (#773)

* fix: remove active user of recipe user when linked

* fix: query

* fix: multitenant user association with account linking (#777)

* fix: test user association

* fix: multitenancy related changes

* fix: pr comments

* fix: pr comments

* fix: merge latest (#782)

* fix: add exp and iat to JWT payloads without scientific notation (#765)

* adding dev-v6.0.9 tag to this commit to ensure building

* fix: fix handling of b64 and b64url encoded access tokens (#767)

* adding dev-v6.0.10 tag to this commit to ensure building

* Update release.md

* Update release.md

* fix: ee featureflag cron job (#778)

* fix: ee featureflag cron job

* fix: test

* fix: tests

* fix: tests

* adding dev-v6.0.11 tag to this commit to ensure building

* fix: test (#779)

* adding dev-v6.0.11 tag to this commit to ensure building

* fix: test (#780)

* fix: test

* fix: test

* adding dev-v6.0.11 tag to this commit to ensure building

* fix: test (#781)

* adding dev-v6.0.11 tag to this commit to ensure building

---------

Co-authored-by: Mihály Lengyel <[email protected]>
Co-authored-by: rishabhpoddar <[email protected]>

* fix: tests (#776)

* fix: tests

* fix: removed removal of active user

* fix: user id mapping deletion

* fix: more fixes

* fix: user delete

* fix: test

* fix: test

* fix: session fix and thirdparty ev test

* fix: pr comments

* fix: pr comments

* fix: tests

* fix: phone number change related

* fix: get user by id as per recipe (#788)

* fix: updated migration (#790)

* fix: updated migration script

* fix: fkey constraint on primary_or_recipe_user_id (#791)

* fix: account linking stats (#792)

* fix: account linking stats

* fix: test

* fix: pr comments

* fix: updated test

* Merge latest 6.0.12 (#795)

* fix: add exp and iat to JWT payloads without scientific notation (#765)

* adding dev-v6.0.9 tag to this commit to ensure building

* fix: fix handling of b64 and b64url encoded access tokens (#767)

* adding dev-v6.0.10 tag to this commit to ensure building

* Update release.md

* Update release.md

* fix: ee featureflag cron job (#778)

* fix: ee featureflag cron job

* fix: test

* fix: tests

* fix: tests

* adding dev-v6.0.11 tag to this commit to ensure building

* fix: test (#779)

* adding dev-v6.0.11 tag to this commit to ensure building

* fix: test (#780)

* fix: test

* fix: test

* adding dev-v6.0.11 tag to this commit to ensure building

* fix: test (#781)

* adding dev-v6.0.11 tag to this commit to ensure building

* Update README.md (#783)

Corrected all the grammatical errors in the README file.

* fix: session concurrency issue (#785)

* adding dev-v6.0.12 tag to this commit to ensure building

* fix: fixing ee folder issue when empty database at startup (#786)

* fix: fixing ee folder issue when empty database at startup

* fix: changelog

* adding dev-v6.0.12 tag to this commit to ensure building

* fix: test (#787)

* fix: fixing ee folder issue when empty database at startup

* fix: changelog

* fix: test

* adding dev-v6.0.12 tag to this commit to ensure building

* bug fixes

* adding dev-v6.0.12 tag to this commit to ensure building

* fix: remove print

---------

Co-authored-by: Mihály Lengyel <[email protected]>
Co-authored-by: rishabhpoddar <[email protected]>
Co-authored-by: Abhisar Yadav <[email protected]>

* fix: tests for tenant association with unlinked account

* fix: email password update email

* fix: shared user in pless

* fix: recipe user association

* fix: ep login issues

* fix: allow user disassociation from all tenant (#799)

* fix: allow user disassociation from all tenants

* fix: multitenancy

* fix: updated changelog

* fix: rename userId to recipeUserId

* fix: function changes (#802)

* fix: account function changes

* fix: function updates

* fix: link and unlink accounts (#803)

* fix: password reset changes (#804)

* fix: adds recipe user id in session (#805)

* fix: fixes query (#806)

* fix: user pagination (#807)

* fix: multitenant user association (#808)

* fix: remove con reuse (#810)

* fix: index updates (#811)

* fix: fkey constraint (#812)

* fix: account linking stats (#813)

* fix: allow tenant disassociation (#814)

* fix: tests (#815)

* fix: tests

* fix: tests

* fix: license stats fix (#818)

* fix: add exp and iat to JWT payloads without scientific notation (#765)

* adding dev-v6.0.9 tag to this commit to ensure building

* fix: fix handling of b64 and b64url encoded access tokens (#767)

* adding dev-v6.0.10 tag to this commit to ensure building

* Update release.md

* Update release.md

* fix: ee featureflag cron job (#778)

* fix: ee featureflag cron job

* fix: test

* fix: tests

* fix: tests

* adding dev-v6.0.11 tag to this commit to ensure building

* fix: test (#779)

* adding dev-v6.0.11 tag to this commit to ensure building

* fix: test (#780)

* fix: test

* fix: test

* adding dev-v6.0.11 tag to this commit to ensure building

* fix: test (#781)

* adding dev-v6.0.11 tag to this commit to ensure building

* Update README.md (#783)

Corrected all the grammatical errors in the README file.

* fix: session concurrency issue (#785)

* adding dev-v6.0.12 tag to this commit to ensure building

* fix: fixing ee folder issue when empty database at startup (#786)

* fix: fixing ee folder issue when empty database at startup

* fix: changelog

* adding dev-v6.0.12 tag to this commit to ensure building

* fix: test (#787)

* fix: fixing ee folder issue when empty database at startup

* fix: changelog

* fix: test

* adding dev-v6.0.12 tag to this commit to ensure building

* bug fixes

* adding dev-v6.0.12 tag to this commit to ensure building

* Update README.md

* Update README.md

* fix: stats fix (#816)

* fix: stats fix

* fix: pr comments

* fix: disable for in mem

* fix: pr comments

* adding dev-v6.0.13 tag to this commit to ensure building

---------

Co-authored-by: Mihály Lengyel <[email protected]>
Co-authored-by: rishabhpoddar <[email protected]>
Co-authored-by: Abhisar Yadav <[email protected]>

* fix: fixes for mongo plugin (#817)

* fix: version and changelog

* fix: schema updates

---------

Co-authored-by: Sattvik Chakravarthy <[email protected]>
Co-authored-by: Mihaly Lengyel <[email protected]>
Co-authored-by: Sattvik Chakravarthy <[email protected]>
Co-authored-by: Abhisar Yadav <[email protected]>
  • Loading branch information
5 people authored Sep 20, 2023
1 parent 071b692 commit 7d29ee6
Show file tree
Hide file tree
Showing 157 changed files with 18,483 additions and 2,612 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ highlighting the necessary changes)
- To know which one it is, run find the latest released tag (`git tag`) in the format `vX.Y.Z`, and then find the
latest branch (`git branch --all`) whose `X.Y` is greater than the latest released tag.
- If no such branch exists, then create one from the latest released branch.

- [ ] If added a foreign key constraint on `app_id_to_user_id` table, make sure to delete from this table when deleting the user as well if `deleteUserIdMappingToo` is false.
## Remaining TODOs for this PR

- [ ] Item1
Expand Down
188 changes: 184 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,187 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased]

## [7.0.0] - 2023-09-19

- Support for CDI version 4.0
- Adds Account Linking feature

### Session recipe changes

- New access token version: v5, which contains a required prop: `rsub`. This contains the recipe user ID that belongs to the login method that the user used to login. The `sub` claim in the access token payload is now the primary user ID.
- APIs that return `SessionInformation` (like GET `/recipe/session`) contains userId, recipeUserId in the response.
- Apis that create / modify / refresh a session return the `recipeUserId` in the `session` object in the response.
- Token theft detected response returns userId and recipeUserId

### Db Schema changes

- Adds columns `primary_or_recipe_user_id`, `is_linked_or_is_a_primary_user` and `primary_or_recipe_user_time_joined` to `all_auth_recipe_users` table
- Adds columns `primary_or_recipe_user_id` and `is_linked_or_is_a_primary_user` to `app_id_to_user_id` table
- Removes index `all_auth_recipe_users_pagination_index` and addes `all_auth_recipe_users_pagination_index1`,
`all_auth_recipe_users_pagination_index2`, `all_auth_recipe_users_pagination_index3` and
`all_auth_recipe_users_pagination_index4` indexes instead on `all_auth_recipe_users` table
- Adds `all_auth_recipe_users_recipe_id_index` on `all_auth_recipe_users` table
- Adds `all_auth_recipe_users_primary_user_id_index` on `all_auth_recipe_users` table
- Adds `email` column to `emailpassword_pswd_reset_tokens` table
- Changes `user_id` foreign key constraint on `emailpassword_pswd_reset_tokens` to `app_id_to_user_id` table

### Migration steps for SQL

1. Ensure that the core is already upgraded to version 6.0.13 (CDI version 3.0)
2. Stop the core instance(s)
3. Run the migration script

<details>

<summary>If using PostgreSQL</summary>

```sql
ALTER TABLE all_auth_recipe_users
ADD COLUMN primary_or_recipe_user_id CHAR(36) NOT NULL DEFAULT ('0');

ALTER TABLE all_auth_recipe_users
ADD COLUMN is_linked_or_is_a_primary_user BOOLEAN NOT NULL DEFAULT FALSE;

ALTER TABLE all_auth_recipe_users
ADD COLUMN primary_or_recipe_user_time_joined BIGINT NOT NULL DEFAULT 0;

UPDATE all_auth_recipe_users
SET primary_or_recipe_user_id = user_id
WHERE primary_or_recipe_user_id = '0';

UPDATE all_auth_recipe_users
SET primary_or_recipe_user_time_joined = time_joined
WHERE primary_or_recipe_user_time_joined = 0;

ALTER TABLE all_auth_recipe_users
ADD CONSTRAINT all_auth_recipe_users_primary_or_recipe_user_id_fkey
FOREIGN KEY (app_id, primary_or_recipe_user_id)
REFERENCES app_id_to_user_id (app_id, user_id) ON DELETE CASCADE;

ALTER TABLE all_auth_recipe_users
ALTER primary_or_recipe_user_id DROP DEFAULT;

ALTER TABLE app_id_to_user_id
ADD COLUMN primary_or_recipe_user_id CHAR(36) NOT NULL DEFAULT ('0');

ALTER TABLE app_id_to_user_id
ADD COLUMN is_linked_or_is_a_primary_user BOOLEAN NOT NULL DEFAULT FALSE;

UPDATE app_id_to_user_id
SET primary_or_recipe_user_id = user_id
WHERE primary_or_recipe_user_id = '0';

ALTER TABLE app_id_to_user_id
ADD CONSTRAINT app_id_to_user_id_primary_or_recipe_user_id_fkey
FOREIGN KEY (app_id, primary_or_recipe_user_id)
REFERENCES app_id_to_user_id (app_id, user_id) ON DELETE CASCADE;

ALTER TABLE app_id_to_user_id
ALTER primary_or_recipe_user_id DROP DEFAULT;

DROP INDEX all_auth_recipe_users_pagination_index;

CREATE INDEX all_auth_recipe_users_pagination_index1 ON all_auth_recipe_users (
app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);

CREATE INDEX all_auth_recipe_users_pagination_index2 ON all_auth_recipe_users (
app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);

CREATE INDEX all_auth_recipe_users_pagination_index3 ON all_auth_recipe_users (
recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);

CREATE INDEX all_auth_recipe_users_pagination_index4 ON all_auth_recipe_users (
recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);

CREATE INDEX all_auth_recipe_users_primary_user_id_index ON all_auth_recipe_users (primary_or_recipe_user_id, app_id);

CREATE INDEX all_auth_recipe_users_recipe_id_index ON all_auth_recipe_users (app_id, recipe_id, tenant_id);

ALTER TABLE emailpassword_pswd_reset_tokens DROP CONSTRAINT IF EXISTS emailpassword_pswd_reset_tokens_user_id_fkey;

ALTER TABLE emailpassword_pswd_reset_tokens ADD CONSTRAINT emailpassword_pswd_reset_tokens_user_id_fkey FOREIGN KEY (app_id, user_id) REFERENCES app_id_to_user_id (app_id, user_id) ON DELETE CASCADE;

ALTER TABLE emailpassword_pswd_reset_tokens ADD COLUMN email VARCHAR(256);
```
</details>

<details>

<summary>If using MySQL</summary>

```sql
ALTER TABLE all_auth_recipe_users
ADD primary_or_recipe_user_id CHAR(36) NOT NULL DEFAULT ('0');
ALTER TABLE all_auth_recipe_users
ADD is_linked_or_is_a_primary_user BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE all_auth_recipe_users
ADD primary_or_recipe_user_time_joined BIGINT UNSIGNED NOT NULL DEFAULT 0;
UPDATE all_auth_recipe_users
SET primary_or_recipe_user_id = user_id
WHERE primary_or_recipe_user_id = '0';
UPDATE all_auth_recipe_users
SET primary_or_recipe_user_time_joined = time_joined
WHERE primary_or_recipe_user_time_joined = 0;
ALTER TABLE all_auth_recipe_users
ADD FOREIGN KEY (app_id, primary_or_recipe_user_id)
REFERENCES app_id_to_user_id (app_id, user_id) ON DELETE CASCADE;
ALTER TABLE all_auth_recipe_users
ALTER primary_or_recipe_user_id DROP DEFAULT;
ALTER TABLE app_id_to_user_id
ADD primary_or_recipe_user_id CHAR(36) NOT NULL DEFAULT ('0');
ALTER TABLE app_id_to_user_id
ADD is_linked_or_is_a_primary_user BOOLEAN NOT NULL DEFAULT FALSE;
UPDATE app_id_to_user_id
SET primary_or_recipe_user_id = user_id
WHERE primary_or_recipe_user_id = '0';
ALTER TABLE app_id_to_user_id
ADD FOREIGN KEY (app_id, primary_or_recipe_user_id)
REFERENCES app_id_to_user_id (app_id, user_id) ON DELETE CASCADE;
ALTER TABLE app_id_to_user_id
ALTER primary_or_recipe_user_id DROP DEFAULT;
DROP INDEX all_auth_recipe_users_pagination_index ON all_auth_recipe_users;
CREATE INDEX all_auth_recipe_users_pagination_index1 ON all_auth_recipe_users (
app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);
CREATE INDEX all_auth_recipe_users_pagination_index2 ON all_auth_recipe_users (
app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);
CREATE INDEX all_auth_recipe_users_pagination_index3 ON all_auth_recipe_users (
recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);
CREATE INDEX all_auth_recipe_users_pagination_index4 ON all_auth_recipe_users (
recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);
CREATE INDEX all_auth_recipe_users_primary_user_id_index ON all_auth_recipe_users (primary_or_recipe_user_id, app_id);
CREATE INDEX all_auth_recipe_users_recipe_id_index ON all_auth_recipe_users (app_id, recipe_id, tenant_id);
ALTER TABLE emailpassword_pswd_reset_tokens
DROP FOREIGN KEY emailpassword_pswd_reset_tokens_ibfk_1;
ALTER TABLE emailpassword_pswd_reset_tokens
ADD FOREIGN KEY (app_id, user_id) REFERENCES app_id_to_user_id (app_id, user_id) ON DELETE CASCADE;
ALTER TABLE emailpassword_pswd_reset_tokens ADD email VARCHAR(256);
```

</details>

4. Start the new instance(s) of the core (version 7.0.0)

## [6.0.13] - 2023-09-15

- Fixes paid stats reporting for multitenancy
Expand Down Expand Up @@ -86,8 +267,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- Support for multitenancy.
- New config `supertokens_saas_secret` added to support multitenancy in SaaS mode.
- New config `supertokens_default_cdi_version` is added to specify the version of CDI core must assume when the
version is not specified in the request. If this config is not specified, the core will assume the latest version.
- New config `supertokens_default_cdi_version` is added to specify the version of CDI core must assume when the version
is not specified in the request. If this config is not specified, the core will assume the latest version.

### Fixes

Expand Down Expand Up @@ -1811,7 +1992,6 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
"key_string": "$keys.value",
"algorithm": "RS256",
"created_at": "$keys.created_at_time",

}
},
{
Expand All @@ -1826,7 +2006,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

}
}
]);
]);
```

- If using `access_token_signing_key_dynamic` true or not set:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compileTestJava { options.encoding = "UTF-8" }
// }
//}

version = "6.0.13"
version = "7.0.0"


repositories {
Expand Down
Binary file modified cli/jar/cli.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion coreDriverInterfaceSupported.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"2.19",
"2.20",
"2.21",
"3.0"
"3.0",
"4.0"
]
}
Binary file modified downloader/jar/downloader.jar
Binary file not shown.
Binary file modified ee/jar/ee.jar
Binary file not shown.
47 changes: 47 additions & 0 deletions ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,49 @@ private JsonObject getMultiTenancyStats()
return stats;
}

private JsonObject getAccountLinkingStats() throws StorageQueryException {
JsonObject result = new JsonObject();
Storage[] storages = StorageLayer.getStoragesForApp(main, this.appIdentifier);
boolean usesAccountLinking = false;

for (Storage storage : storages) {
if (((AuthRecipeStorage)storage).checkIfUsesAccountLinking(this.appIdentifier)) {
usesAccountLinking = true;
break;
}
}

result.addProperty("usesAccountLinking", usesAccountLinking);
if (!usesAccountLinking) {
result.addProperty("totalUserCountWithMoreThanOneLoginMethod", 0);
JsonArray mauArray = new JsonArray();
for (int i = 0; i < 30; i++) {
mauArray.add(new JsonPrimitive(0));
}
result.add("mauWithMoreThanOneLoginMethod", mauArray);
return result;
}

int totalUserCountWithMoreThanOneLoginMethod = 0;
int[] maus = new int[30];

long now = System.currentTimeMillis();
long today = now - (now % (24 * 60 * 60 * 1000L));

for (Storage storage : storages) {
totalUserCountWithMoreThanOneLoginMethod += ((AuthRecipeStorage)storage).getUsersCountWithMoreThanOneLoginMethod(this.appIdentifier);

for (int i = 0; i < 30; i++) {
long timestamp = today - (i * 24 * 60 * 60 * 1000L);
maus[i] += ((ActiveUsersStorage)storage).countUsersThatHaveMoreThanOneLoginMethodAndActiveSince(appIdentifier, timestamp);
}
}

result.addProperty("totalUserCountWithMoreThanOneLoginMethod", totalUserCountWithMoreThanOneLoginMethod);
result.add("mauWithMoreThanOneLoginMethod", new Gson().toJsonTree(maus));
return result;
}

private JsonArray getMAUs() throws StorageQueryException, TenantOrAppNotFoundException {
JsonArray mauArr = new JsonArray();
for (int i = 0; i < 30; i++) {
Expand Down Expand Up @@ -319,6 +362,10 @@ public JsonObject getPaidFeatureStats() throws StorageQueryException, TenantOrAp
if (feature == EE_FEATURES.MULTI_TENANCY) {
usageStats.add(EE_FEATURES.MULTI_TENANCY.toString(), getMultiTenancyStats());
}

if (feature == EE_FEATURES.ACCOUNT_LINKING) {
usageStats.add(EE_FEATURES.ACCOUNT_LINKING.toString(), getAccountLinkingStats());
}
}

usageStats.add("maus", getMAUs());
Expand Down
Binary file renamed jar/core-6.0.13.jar → jar/core-7.0.0.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pluginInterfaceSupported.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"_comment": "contains a list of plugin interfaces branch names that this core supports",
"versions": [
"3.0"
"4.0"
]
}
16 changes: 16 additions & 0 deletions src/main/java/io/supertokens/ActiveUsers.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.supertokens;

import io.supertokens.pluginInterface.authRecipe.sqlStorage.AuthRecipeSQLStorage;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifierWithStorage;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.storageLayer.StorageLayer;
Expand Down Expand Up @@ -37,4 +39,18 @@ public static int countUsersActiveSince(Main main, long time)
return countUsersActiveSince(new AppIdentifierWithStorage(null, null, StorageLayer.getStorage(main)), main,
time);
}

public static void removeActiveUser(AppIdentifierWithStorage appIdentifierWithStorage, String userId)
throws StorageQueryException {
try {
((AuthRecipeSQLStorage) appIdentifierWithStorage.getActiveUsersStorage()).startTransaction(con -> {
appIdentifierWithStorage.getActiveUsersStorage().deleteUserActive_Transaction(con, appIdentifierWithStorage, userId);
((AuthRecipeSQLStorage) appIdentifierWithStorage.getActiveUsersStorage()).commitTransaction(con);
return null;
});

} catch (StorageTransactionLogicException e) {
throw new StorageQueryException(e.actualException);
}
}
}
Loading

0 comments on commit 7d29ee6

Please sign in to comment.