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

feat: account linking #742

Merged
merged 149 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
e648127
table schema changes
rishabhpoddar Jul 7, 2023
c450627
changes to user count API
rishabhpoddar Jul 7, 2023
0bbb9a7
small change
rishabhpoddar Jul 7, 2023
ee69339
implements changes to auth queries to fetch tenant ids and verified s…
rishabhpoddar Jul 8, 2023
1116e93
fixes a few bugs
rishabhpoddar Jul 9, 2023
c1e6e16
more changes
rishabhpoddar Jul 10, 2023
1f819e4
fixes query
rishabhpoddar Jul 10, 2023
c21240a
fixes tests
rishabhpoddar Jul 10, 2023
c15c299
all test fixes
rishabhpoddar Jul 10, 2023
878bc16
removes a few unnecessary functions
rishabhpoddar Jul 11, 2023
aab92ff
uses new interface to fetch user based on id
rishabhpoddar Jul 11, 2023
810fcc3
adds stub for new function
rishabhpoddar Jul 11, 2023
b96f0e6
removes use of unnecessary function
rishabhpoddar Jul 11, 2023
f9d5f9b
changes based on interface
rishabhpoddar Jul 12, 2023
8dd0ea4
adds function for list user by phone number
rishabhpoddar Jul 12, 2023
c0759fd
optimises a query
rishabhpoddar Jul 12, 2023
bbf76f0
merges with latest
rishabhpoddar Jul 12, 2023
f1928f3
more intefrace function
rishabhpoddar Jul 12, 2023
9b44206
Merge branch '6.0' into feat/account-linking
rishabhpoddar Jul 13, 2023
132ae3f
removes unused interface func
rishabhpoddar Jul 14, 2023
0907a20
Merge branch '6.0' into feat/account-linking
rishabhpoddar Jul 14, 2023
04f7fda
Merge branch '6.0' into feat/account-linking
rishabhpoddar Jul 14, 2023
55f0a87
adds migration script to changelog
rishabhpoddar Jul 15, 2023
9a8b9ca
small changes
rishabhpoddar Jul 15, 2023
8d4e2e3
refactor
rishabhpoddar Jul 15, 2023
2e2feea
removes unneeded functions
rishabhpoddar Jul 15, 2023
a86a63f
adds user get API
rishabhpoddar Jul 17, 2023
858b129
get users by account info API
rishabhpoddar Jul 17, 2023
fc8d47b
adds new func signature
rishabhpoddar Jul 17, 2023
6c773f1
Merge branch '6.0' into feat/account-linking
rishabhpoddar Jul 17, 2023
1f48803
creates new indices
rishabhpoddar Jul 17, 2023
a49d73e
adds impl for creating a primary user
rishabhpoddar Jul 17, 2023
9d03ca1
Merge branch '6.0' into feat/account-linking
rishabhpoddar Jul 17, 2023
c54475a
implements one of the functions
rishabhpoddar Jul 17, 2023
f339e48
Merge branch '6.0' into feat/account-linking
rishabhpoddar Jul 20, 2023
9f7e9ac
adds more query impls
rishabhpoddar Jul 21, 2023
8b6a9bf
Merge branch '6.0' into feat/account-linking
rishabhpoddar Jul 24, 2023
c538b6e
Merge branch '6.0' into feat/account-linking
rishabhpoddar Jul 24, 2023
7dd2d60
Merge branch '6.0' into feat/account-linking
rishabhpoddar Jul 24, 2023
5e4568e
fixes small issue
rishabhpoddar Jul 25, 2023
c48f7fc
Merge branch '6.0' into feat/account-linking
rishabhpoddar Jul 25, 2023
af7b850
starts working on account linking tests
rishabhpoddar Jul 25, 2023
6c2f281
adds a few tests
rishabhpoddar Jul 26, 2023
a3dafdd
adds more tests
rishabhpoddar Jul 26, 2023
7654819
more tests
rishabhpoddar Jul 26, 2023
38eb251
adds link account function
rishabhpoddar Jul 26, 2023
d8cd803
removes unneeded index
rishabhpoddar Jul 26, 2023
73846ca
adds test only func and also adds feature flag check
rishabhpoddar Jul 26, 2023
ffed7e1
more changes
rishabhpoddar Jul 26, 2023
a753685
adds one account linking test
rishabhpoddar Jul 26, 2023
7f16304
adds more tests
rishabhpoddar Jul 26, 2023
d1c7c75
more tests
rishabhpoddar Jul 26, 2023
ab8206d
more tests
rishabhpoddar Jul 27, 2023
772ebc1
more tests
rishabhpoddar Jul 27, 2023
3ef4c42
more tests
rishabhpoddar Jul 27, 2023
9b7a593
mods delete function
rishabhpoddar Jul 27, 2023
be3e2ab
merges with latest
rishabhpoddar Jul 28, 2023
26daade
small file change
rishabhpoddar Jul 28, 2023
c16466e
merges with latest
rishabhpoddar Jul 28, 2023
5c29004
delete function change
rishabhpoddar Jul 31, 2023
64e9ca2
fixes a bug
rishabhpoddar Jul 31, 2023
4aa16dc
adds more tests
rishabhpoddar Jul 31, 2023
e770c2f
adds unliking accounts function
rishabhpoddar Jul 31, 2023
4b9d85e
refactors for link accounts function
rishabhpoddar Jul 31, 2023
eb01313
more refactor
rishabhpoddar Jul 31, 2023
0816462
adds API for can create primary user
rishabhpoddar Aug 1, 2023
4ee69c6
adds create primary user API, except for converting tuser obj to json
rishabhpoddar Aug 1, 2023
03b036c
fixes older APIs
rishabhpoddar Aug 1, 2023
840962d
fixes tests
rishabhpoddar Aug 1, 2023
96a0b26
merges with latest
rishabhpoddar Aug 1, 2023
246f439
removes unneeded file
rishabhpoddar Aug 1, 2023
cbd05ce
starts working on can link accounts api
rishabhpoddar Aug 2, 2023
7a97193
adds more tests
rishabhpoddar Aug 2, 2023
7e72d76
more tests
rishabhpoddar Aug 2, 2023
aa7cb15
new tests
rishabhpoddar Aug 2, 2023
50b9a53
adds tests for linking accounts API
rishabhpoddar Aug 2, 2023
de5588f
adds unlink accounts API
rishabhpoddar Aug 3, 2023
a7776b9
adds more tests
rishabhpoddar Aug 3, 2023
3057fcc
more changes
rishabhpoddar Aug 3, 2023
b5126b0
changes for password reset flow
rishabhpoddar Aug 3, 2023
e57d7e3
more tests
rishabhpoddar Aug 3, 2023
ec19d79
more tests
rishabhpoddar Aug 3, 2023
4ff84c4
implements consumeCode function
rishabhpoddar Aug 3, 2023
d28cb7c
adds API to consume reset password code
rishabhpoddar Aug 3, 2023
9b3b063
adds more tests
rishabhpoddar Aug 4, 2023
b864e2f
adds more tests
rishabhpoddar Aug 4, 2023
2c7637c
removes unnecessary comment
rishabhpoddar Aug 4, 2023
2f868cf
adds more tests
rishabhpoddar Aug 4, 2023
33b6f27
updates to updatemeailorpassword function
rishabhpoddar Aug 4, 2023
63bf189
adds more tests
rishabhpoddar Aug 4, 2023
3b1af33
updates tp sign in to check for email update allowance
rishabhpoddar Aug 4, 2023
f08a9a4
more tests
rishabhpoddar Aug 4, 2023
0f7152d
adds more tests
rishabhpoddar Aug 4, 2023
7f4e46a
fixes a bug
rishabhpoddar Aug 4, 2023
c5fddf4
adds recipe user id in session
rishabhpoddar Aug 5, 2023
38ef5db
adds session changes to changelog
rishabhpoddar Aug 5, 2023
6f148bf
changes claim ro rsub
rishabhpoddar Aug 5, 2023
1424ad4
changes API spec
rishabhpoddar Aug 5, 2023
f1b91ca
changes API spec
rishabhpoddar Aug 5, 2023
2b57539
changes to passwordless recipe update user
rishabhpoddar Aug 5, 2023
fc4fba0
renames variable
rishabhpoddar Aug 5, 2023
0676447
fix: account linking tests (#764)
sattvikc Aug 16, 2023
8adea4e
fix: user pagination changes (#766)
sattvikc Aug 16, 2023
177efff
fix: remove extra wrapper around user objects in users list
porcellus Aug 18, 2023
d2af404
feat: update latest access token version
porcellus Aug 18, 2023
b4e9936
fix: user pagination tests (#768)
sattvikc Aug 23, 2023
cd3c36e
fix: recipeUserId in sign in/up related APIs (#769)
sattvikc Aug 24, 2023
bd0062b
fix: External userid (#770)
sattvikc Aug 25, 2023
0a79d5a
fix: user object in link accounts api (#771)
sattvikc Aug 25, 2023
3ce68da
fix: remove UserInfo class (#772)
sattvikc Aug 26, 2023
446d282
fix: emailverified in tp & pless (#774)
sattvikc Aug 28, 2023
97eca33
fix: remove active user of recipe user when linked (#773)
sattvikc Aug 28, 2023
5e0fb6f
fix: multitenant user association with account linking (#777)
sattvikc Aug 31, 2023
de76ce8
fix: merge latest (#782)
sattvikc Sep 1, 2023
3e39d0b
fix: tests (#776)
sattvikc Sep 6, 2023
265dbda
fix: get user by id as per recipe (#788)
sattvikc Sep 6, 2023
bd99d66
fix: updated migration (#790)
sattvikc Sep 7, 2023
82a2216
fix: updated migration script
sattvikc Sep 7, 2023
d8569da
fix: fkey constraint on primary_or_recipe_user_id (#791)
sattvikc Sep 7, 2023
f7e4d6b
fix: account linking stats (#792)
sattvikc Sep 7, 2023
6e4237c
Merge latest 6.0.12 (#795)
sattvikc Sep 11, 2023
96954fe
fix: tests for tenant association with unlinked account
sattvikc Sep 11, 2023
627ba81
fix: email password update email
sattvikc Sep 11, 2023
6986b33
fix: shared user in pless
sattvikc Sep 11, 2023
e90c778
fix: recipe user association
sattvikc Sep 11, 2023
1a9ae87
Merge pull request #796 from supertokens/al-misc-changes
porcellus Sep 11, 2023
18ca94c
fix: ep login issues
sattvikc Sep 11, 2023
a2d8d61
Merge pull request #798 from supertokens/al-ep-issue
porcellus Sep 11, 2023
1971c2c
fix: allow user disassociation from all tenant (#799)
sattvikc Sep 13, 2023
3bdc244
fix: rename userId to recipeUserId
sattvikc Sep 13, 2023
b785061
Merge pull request #801 from supertokens/rename-userid
porcellus Sep 13, 2023
106ad73
fix: function changes (#802)
sattvikc Sep 13, 2023
8daf1d1
fix: link and unlink accounts (#803)
sattvikc Sep 13, 2023
36098ff
fix: password reset changes (#804)
sattvikc Sep 13, 2023
57ce073
fix: adds recipe user id in session (#805)
sattvikc Sep 13, 2023
f73a02f
fix: fixes query (#806)
sattvikc Sep 13, 2023
825c13f
fix: user pagination (#807)
sattvikc Sep 13, 2023
f721e15
fix: multitenant user association (#808)
sattvikc Sep 13, 2023
21e4ec9
fix: remove con reuse (#810)
sattvikc Sep 14, 2023
1c9ace2
fix: index updates (#811)
sattvikc Sep 14, 2023
91673ad
fix: fkey constraint (#812)
sattvikc Sep 14, 2023
da21390
fix: account linking stats (#813)
sattvikc Sep 14, 2023
0a22121
fix: allow tenant disassociation (#814)
sattvikc Sep 14, 2023
35dd880
fix: tests (#815)
sattvikc Sep 14, 2023
e993e14
fix: license stats fix (#818)
sattvikc Sep 19, 2023
abdcfbc
fix: fixes for mongo plugin (#817)
sattvikc Sep 19, 2023
d663893
fix: version and changelog
sattvikc Sep 19, 2023
43d1a6d
fix: schema updates
sattvikc Sep 19, 2023
0b102d3
Merge branch '6.0' into feat/account-linking
sattvikc Sep 19, 2023
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 .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
Loading