Skip to content

Commit 0b5c225

Browse files
authored
fix: fixes storage handling for non-auth recipes (#140)
* fix: non auth stuff * fix: AppIdentifier * fix: interface changes * fix: multitenancy storage * fix: update add user role * fix: cleanup * fix: user role storage updates * fix: user roles * fix: version and changelog
1 parent 1933948 commit 0b5c225

File tree

11 files changed

+147
-315
lines changed

11 files changed

+147
-315
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
99

10+
## [5.0.0] - 2024-03-05
11+
12+
- Removes types `AppIdentifierWithStorage` and `TenantIdentifierWithStorage`
13+
- Adds `deleteAllUserRoleAssociationsForRole` function to `UserRolesStorage`
14+
1015
## [4.0.5] - 2023-12-05
1116

1217
- Adds `InvalidConfigException` to throws list of `canBeUsed` function

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id 'java-library'
33
}
44

5-
version = "4.0.5"
5+
version = "5.0.0"
66

77
repositories {
88
mavenCentral()
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved.
3+
*
4+
* This software is licensed under the Apache License, Version 2.0 (the
5+
* "License") as published by the Apache Software Foundation.
6+
*
7+
* You may not use this file except in compliance with the License. You may
8+
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package io.supertokens.pluginInterface;
18+
19+
import io.supertokens.pluginInterface.authRecipe.AuthRecipeStorage;
20+
import io.supertokens.pluginInterface.authRecipe.sqlStorage.AuthRecipeSQLStorage;
21+
import io.supertokens.pluginInterface.dashboard.sqlStorage.DashboardSQLStorage;
22+
import io.supertokens.pluginInterface.emailpassword.sqlStorage.EmailPasswordSQLStorage;
23+
import io.supertokens.pluginInterface.emailverification.sqlStorage.EmailVerificationSQLStorage;
24+
import io.supertokens.pluginInterface.multitenancy.MultitenancyStorage;
25+
import io.supertokens.pluginInterface.passwordless.sqlStorage.PasswordlessSQLStorage;
26+
import io.supertokens.pluginInterface.session.SessionStorage;
27+
import io.supertokens.pluginInterface.thirdparty.sqlStorage.ThirdPartySQLStorage;
28+
import io.supertokens.pluginInterface.totp.sqlStorage.TOTPSQLStorage;
29+
import io.supertokens.pluginInterface.useridmapping.UserIdMappingStorage;
30+
import io.supertokens.pluginInterface.usermetadata.sqlStorage.UserMetadataSQLStorage;
31+
import io.supertokens.pluginInterface.userroles.sqlStorage.UserRolesSQLStorage;
32+
33+
public class StorageUtils {
34+
public static AuthRecipeSQLStorage getAuthRecipeStorage(Storage storage) {
35+
if (storage.getType() != STORAGE_TYPE.SQL) {
36+
// we only support SQL for now
37+
throw new UnsupportedOperationException("");
38+
}
39+
40+
return (AuthRecipeSQLStorage) storage;
41+
}
42+
43+
public static EmailPasswordSQLStorage getEmailPasswordStorage(Storage storage) {
44+
if (storage.getType() != STORAGE_TYPE.SQL) {
45+
// we only support SQL for now
46+
throw new UnsupportedOperationException("");
47+
}
48+
return (EmailPasswordSQLStorage) storage;
49+
}
50+
51+
public static PasswordlessSQLStorage getPasswordlessStorage(Storage storage) {
52+
if (storage.getType() != STORAGE_TYPE.SQL) {
53+
// we only support SQL for now
54+
throw new UnsupportedOperationException("");
55+
}
56+
return (PasswordlessSQLStorage) storage;
57+
}
58+
59+
public static ThirdPartySQLStorage getThirdPartyStorage(Storage storage) {
60+
if (storage.getType() != STORAGE_TYPE.SQL) {
61+
// we only support SQL for now
62+
throw new UnsupportedOperationException("");
63+
}
64+
return (ThirdPartySQLStorage) storage;
65+
}
66+
67+
public static EmailVerificationSQLStorage getEmailVerificationStorage(Storage storage) {
68+
if (storage.getType() != STORAGE_TYPE.SQL) {
69+
// we only support SQL for now
70+
throw new UnsupportedOperationException("");
71+
}
72+
return (EmailVerificationSQLStorage) storage;
73+
}
74+
75+
public static SessionStorage getSessionStorage(Storage storage) {
76+
return (SessionStorage) storage;
77+
}
78+
79+
public static UserMetadataSQLStorage getUserMetadataStorage(Storage storage) {
80+
if (storage.getType() != STORAGE_TYPE.SQL) {
81+
// we only support SQL for now
82+
throw new UnsupportedOperationException("");
83+
}
84+
85+
return (UserMetadataSQLStorage) storage;
86+
}
87+
88+
public static UserIdMappingStorage getUserIdMappingStorage(Storage storage) {
89+
if (storage.getType() != STORAGE_TYPE.SQL) {
90+
// we only support SQL for now
91+
throw new UnsupportedOperationException("");
92+
}
93+
94+
return (UserIdMappingStorage) storage;
95+
}
96+
97+
public static UserRolesSQLStorage getUserRolesStorage(Storage storage) {
98+
if (storage.getType() != STORAGE_TYPE.SQL) {
99+
// we only support SQL for now
100+
throw new UnsupportedOperationException("");
101+
}
102+
return (UserRolesSQLStorage) storage;
103+
}
104+
105+
public static DashboardSQLStorage getDashboardStorage(Storage storage) {
106+
if (storage.getType() != STORAGE_TYPE.SQL) {
107+
// we only support SQL for now
108+
throw new UnsupportedOperationException("");
109+
}
110+
return (DashboardSQLStorage) storage;
111+
}
112+
113+
public static TOTPSQLStorage getTOTPStorage(Storage storage) {
114+
if (storage.getType() != STORAGE_TYPE.SQL) {
115+
// we only support SQL for now
116+
throw new UnsupportedOperationException("");
117+
}
118+
return (TOTPSQLStorage) storage;
119+
}
120+
121+
public static ActiveUsersStorage getActiveUsersStorage(Storage storage) {
122+
if (storage.getType() != STORAGE_TYPE.SQL) {
123+
// we only support SQL for now
124+
throw new UnsupportedOperationException("");
125+
}
126+
return (ActiveUsersStorage) storage;
127+
}
128+
129+
public static MultitenancyStorage getMultitenancyStorage(Storage storage) {
130+
if (storage.getType() != STORAGE_TYPE.SQL) {
131+
// we only support SQL for now
132+
throw new UnsupportedOperationException("");
133+
}
134+
return (MultitenancyStorage) storage;
135+
}
136+
}

src/main/java/io/supertokens/pluginInterface/authRecipe/sqlStorage/AuthRecipeSQLStorage.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo;
2121
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
2222
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
23-
import io.supertokens.pluginInterface.multitenancy.AppIdentifierWithStorage;
2423
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
2524
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;
2625

src/main/java/io/supertokens/pluginInterface/multitenancy/AppIdentifier.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,4 @@ public int hashCode() {
8080
public TenantIdentifier getAsPublicTenantIdentifier() {
8181
return new TenantIdentifier(this.getConnectionUriDomain(), this.getAppId(), null);
8282
}
83-
84-
public AppIdentifierWithStorage withStorage(Storage storage) {
85-
return new AppIdentifierWithStorage(this.getConnectionUriDomain(), this.getAppId(), storage);
86-
}
8783
}

src/main/java/io/supertokens/pluginInterface/multitenancy/AppIdentifierWithStorage.java

Lines changed: 0 additions & 162 deletions
This file was deleted.

src/main/java/io/supertokens/pluginInterface/multitenancy/MultitenancyStorage.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,11 @@
1717
package io.supertokens.pluginInterface.multitenancy;
1818

1919
import io.supertokens.pluginInterface.Storage;
20-
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateEmailException;
21-
import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException;
2220
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
2321
import io.supertokens.pluginInterface.multitenancy.exceptions.DuplicateClientTypeException;
2422
import io.supertokens.pluginInterface.multitenancy.exceptions.DuplicateTenantException;
2523
import io.supertokens.pluginInterface.multitenancy.exceptions.DuplicateThirdPartyIdException;
2624
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
27-
import io.supertokens.pluginInterface.passwordless.exception.DuplicatePhoneNumberException;
28-
import io.supertokens.pluginInterface.thirdparty.exception.DuplicateThirdPartyUserException;
29-
import io.supertokens.pluginInterface.userroles.exception.UnknownRoleException;
3025

3126
public interface MultitenancyStorage extends Storage {
3227

src/main/java/io/supertokens/pluginInterface/multitenancy/TenantIdentifier.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,4 @@ public int hashCode() {
8787
public AppIdentifier toAppIdentifier() {
8888
return new AppIdentifier(this.getConnectionUriDomain(), this.getAppId());
8989
}
90-
91-
public TenantIdentifierWithStorage withStorage(Storage storage) {
92-
return new TenantIdentifierWithStorage(this.getConnectionUriDomain(), this.getAppId(), this.getTenantId(),
93-
storage);
94-
}
9590
}

0 commit comments

Comments
 (0)