diff --git a/modules/auth_email/scripts/verify_add_email_pass.ts b/modules/auth_email/scripts/verify_add_email_pass.ts index fae6c48a..157ba711 100644 --- a/modules/auth_email/scripts/verify_add_email_pass.ts +++ b/modules/auth_email/scripts/verify_add_email_pass.ts @@ -30,7 +30,7 @@ export async function run( } // Ensure that the email is not associated with ANY accounts in ANY way. - const providedUser = await ctx.modules.users.authenticateToken({ + const providedUser = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken, }); await ensureNotAssociatedAll(ctx, email, new Set([providedUser.userId])); diff --git a/modules/auth_email/scripts/verify_add_no_pass.ts b/modules/auth_email/scripts/verify_add_no_pass.ts index 5181c657..5c574b3f 100644 --- a/modules/auth_email/scripts/verify_add_no_pass.ts +++ b/modules/auth_email/scripts/verify_add_no_pass.ts @@ -21,7 +21,7 @@ export async function run( const { email } = await verifyCode(ctx, req.verificationToken, req.code); // Ensure that the email is not already associated with another account - const providedUser = await ctx.modules.users.authenticateToken({ + const providedUser = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken, }); await ensureNotAssociatedAll(ctx, email, new Set([providedUser.userId])); diff --git a/modules/auth_email/scripts/verify_link_email.ts b/modules/auth_email/scripts/verify_link_email.ts index 680a4847..64a62524 100644 --- a/modules/auth_email/scripts/verify_link_email.ts +++ b/modules/auth_email/scripts/verify_link_email.ts @@ -21,7 +21,7 @@ export async function run( const { email } = await verifyCode(ctx, req.verificationToken, req.code); // Ensure that the email is not already associated with another account - const providedUser = await ctx.modules.users.authenticateToken({ + const providedUser = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken, }); await ensureNotAssociatedAll(ctx, email, new Set([providedUser.userId])); diff --git a/modules/auth_email/tests/already_used.ts b/modules/auth_email/tests/already_used.ts index bc79ada5..3b070fd5 100644 --- a/modules/auth_email/tests/already_used.ts +++ b/modules/auth_email/tests/already_used.ts @@ -129,7 +129,7 @@ test("email_link_then_add_pass", async (ctx: TestContext) => { const password = faker.internet.password(); const { userToken } = await signUpEmailLink(ctx, email); - const { user } = await ctx.modules.users.authenticateToken({ + const { user } = await ctx.modules.users.authenticateTokenInternal({ userToken, fetchUser: true, }); @@ -161,7 +161,7 @@ test("email_link_then_add_no_pass", async (ctx: TestContext) => { const email = faker.internet.email(); const { userToken } = await signUpEmailLink(ctx, email); - const { user } = await ctx.modules.users.authenticateToken({ + const { user } = await ctx.modules.users.authenticateTokenInternal({ userToken, fetchUser: true, }); diff --git a/modules/auth_email/tests/common.ts b/modules/auth_email/tests/common.ts index 8f0179d4..0572859c 100644 --- a/modules/auth_email/tests/common.ts +++ b/modules/auth_email/tests/common.ts @@ -45,7 +45,7 @@ export async function checkLogin( newToken: string, ) { const { userId: signedInUserId, user: signedInUser } = await ctx.modules.users - .authenticateToken({ + .authenticateTokenInternal({ userToken: newToken, fetchUser: true, }); diff --git a/modules/auth_email/tests/create.ts b/modules/auth_email/tests/create.ts index b4c9780a..2e6de889 100644 --- a/modules/auth_email/tests/create.ts +++ b/modules/auth_email/tests/create.ts @@ -22,7 +22,7 @@ test("create_with_email_and_login_passwordless", async (ctx: TestContext) => { userToken = signUpRes.userToken; } - const { user } = await ctx.modules.users.authenticateToken({ + const { user } = await ctx.modules.users.authenticateTokenInternal({ userToken, fetchUser: true, }); @@ -65,7 +65,7 @@ test("create_with_email_and_login_password", async (ctx: TestContext) => { userToken = signUpRes.userToken; } - const { user } = await ctx.modules.users.authenticateToken({ + const { user } = await ctx.modules.users.authenticateTokenInternal({ userToken, fetchUser: true, }); diff --git a/modules/auth_email/utils/link_assertions.ts b/modules/auth_email/utils/link_assertions.ts index 62939197..969e432a 100644 --- a/modules/auth_email/utils/link_assertions.ts +++ b/modules/auth_email/utils/link_assertions.ts @@ -41,7 +41,7 @@ export async function ensureNotAssociated( } } // Email matches an existing identity using this provider - const existingUser = await ctx.modules.users.authenticateToken( + const existingUser = await ctx.modules.users.authenticateTokenInternal( existingIdentity, ); diff --git a/modules/auth_username_password/tests/e2e.ts b/modules/auth_username_password/tests/e2e.ts index 64ba9651..f4bc1424 100644 --- a/modules/auth_username_password/tests/e2e.ts +++ b/modules/auth_username_password/tests/e2e.ts @@ -13,7 +13,7 @@ test("test_sign_up", async (ctx: TestContext) => { password, }); - const { userId } = await ctx.modules.users.authenticateToken({ + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: token.token, }); @@ -51,7 +51,7 @@ test("test_sign_in", async (ctx: TestContext) => { password, }); - const { userId } = await ctx.modules.users.authenticateToken({ + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: token.token, }); diff --git a/modules/currency/scripts/fetch_balance_by_token.ts b/modules/currency/scripts/fetch_balance_by_token.ts index 57be082f..5bdeae60 100644 --- a/modules/currency/scripts/fetch_balance_by_token.ts +++ b/modules/currency/scripts/fetch_balance_by_token.ts @@ -15,7 +15,7 @@ export async function run( ): Promise { await ctx.modules.rateLimit.throttlePublic({ requests: 25 }); - const { userId } = await ctx.modules.users.authenticateToken({ + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken, }); const { balance } = await ctx.modules.currency.fetchBalance({ userId }); diff --git a/modules/friends/scripts/accept_request.ts b/modules/friends/scripts/accept_request.ts index aafbe3c6..d1dd300f 100644 --- a/modules/friends/scripts/accept_request.ts +++ b/modules/friends/scripts/accept_request.ts @@ -13,7 +13,7 @@ export async function run( ): Promise { await ctx.modules.rateLimit.throttlePublic({ requests: 50 }); - const { userId } = await ctx.modules.users.authenticateToken({ + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken, }); diff --git a/modules/friends/scripts/decline_request.ts b/modules/friends/scripts/decline_request.ts index 686f0496..d0a9096c 100644 --- a/modules/friends/scripts/decline_request.ts +++ b/modules/friends/scripts/decline_request.ts @@ -13,7 +13,7 @@ export async function run( ): Promise { await ctx.modules.rateLimit.throttlePublic({ requests: 50 }); - const { userId } = await ctx.modules.users.authenticateToken({ + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken, }); diff --git a/modules/friends/scripts/list_friends.ts b/modules/friends/scripts/list_friends.ts index 4e2625b1..43fbf439 100644 --- a/modules/friends/scripts/list_friends.ts +++ b/modules/friends/scripts/list_friends.ts @@ -15,7 +15,7 @@ export async function run( ): Promise { await ctx.modules.rateLimit.throttlePublic({ requests: 50 }); - const { userId } = await ctx.modules.users.authenticateToken({ + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken, }); diff --git a/modules/friends/scripts/list_incoming_friend_requests.ts b/modules/friends/scripts/list_incoming_friend_requests.ts index c135dc2b..e8d0a898 100644 --- a/modules/friends/scripts/list_incoming_friend_requests.ts +++ b/modules/friends/scripts/list_incoming_friend_requests.ts @@ -15,7 +15,7 @@ export async function run( ): Promise { await ctx.modules.rateLimit.throttlePublic({ requests: 50 }); - const { userId } = await ctx.modules.users.authenticateToken({ + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken, }); diff --git a/modules/friends/scripts/list_outgoing_friend_requests.ts b/modules/friends/scripts/list_outgoing_friend_requests.ts index d54cdb51..5a1878a9 100644 --- a/modules/friends/scripts/list_outgoing_friend_requests.ts +++ b/modules/friends/scripts/list_outgoing_friend_requests.ts @@ -15,7 +15,7 @@ export async function run( ): Promise { await ctx.modules.rateLimit.throttlePublic({}); - const { userId } = await ctx.modules.users.authenticateToken({ + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken, }); diff --git a/modules/friends/scripts/remove_friend.ts b/modules/friends/scripts/remove_friend.ts index 62541e11..4a16e2a9 100644 --- a/modules/friends/scripts/remove_friend.ts +++ b/modules/friends/scripts/remove_friend.ts @@ -13,7 +13,7 @@ export async function run( ): Promise { await ctx.modules.rateLimit.throttlePublic({ requests: 50 }); - const { userId } = await ctx.modules.users.authenticateToken({ + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken, }); diff --git a/modules/friends/scripts/send_request.ts b/modules/friends/scripts/send_request.ts index 3321ee93..47c3da4f 100644 --- a/modules/friends/scripts/send_request.ts +++ b/modules/friends/scripts/send_request.ts @@ -16,7 +16,7 @@ export async function run( ): Promise { await ctx.modules.rateLimit.throttlePublic({}); - const { userId } = await ctx.modules.users.authenticateToken({ + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken, }); diff --git a/modules/identities/scripts/fetch.ts b/modules/identities/scripts/fetch.ts index e8a33dfc..eea6d323 100644 --- a/modules/identities/scripts/fetch.ts +++ b/modules/identities/scripts/fetch.ts @@ -18,7 +18,7 @@ export async function run( req: Request, ): Promise { // Ensure the user token is valid and get the user ID - const { userId } = await ctx.modules.users.authenticateToken({ userToken: req.userToken }); + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken }); // Get identity data const identity = await ctx.db.query.userIdentities.findFirst({ diff --git a/modules/identities/scripts/link.ts b/modules/identities/scripts/link.ts index b69dde6a..1d65e70e 100644 --- a/modules/identities/scripts/link.ts +++ b/modules/identities/scripts/link.ts @@ -18,7 +18,7 @@ export async function run( ): Promise { // Ensure the user token is valid and get the user ID - const { userId } = await ctx.modules.users.authenticateToken({ userToken: req.userToken } ); + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken } ); return await ctx.db.transaction(async (tx) => { // Error if this identity provider is ALREADY associated with the user diff --git a/modules/identities/scripts/list.ts b/modules/identities/scripts/list.ts index cedc79b0..912e1fd3 100644 --- a/modules/identities/scripts/list.ts +++ b/modules/identities/scripts/list.ts @@ -16,7 +16,7 @@ export async function run( await ctx.modules.rateLimit.throttlePublic({}); // Ensure the user token is valid and get the user ID - const { userId } = await ctx.modules.users.authenticateToken({ userToken: req.userToken } ); + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken } ); const identityProviders = await ctx.db.query.userIdentities.findMany({ where: Query.eq(Database.userIdentities.userId, userId), diff --git a/modules/identities/scripts/set.ts b/modules/identities/scripts/set.ts index 1268f91c..1eebb7f4 100644 --- a/modules/identities/scripts/set.ts +++ b/modules/identities/scripts/set.ts @@ -15,7 +15,7 @@ export async function run( req: Request, ): Promise { // Ensure the user token is valid and get the user ID - const { userId } = await ctx.modules.users.authenticateToken({ userToken: req.userToken } ); + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: req.userToken } ); await ctx.db.transaction(async (tx) => { // Ensure the identity provider is associated with the user diff --git a/modules/identities/tests/sign_up.ts b/modules/identities/tests/sign_up.ts index 00ba5fff..3b03d0ef 100644 --- a/modules/identities/tests/sign_up.ts +++ b/modules/identities/tests/sign_up.ts @@ -14,7 +14,7 @@ export async function signUpWithTest(ctx: TestContext, username: string, uniqueD additionalData, }); - const { userId, user } = await ctx.modules.users.authenticateToken({ + const { userId, user } = await ctx.modules.users.authenticateTokenInternal({ userToken, fetchUser: true, }); @@ -34,7 +34,7 @@ export async function signInWithTest(ctx: TestContext, uniqueData: any) { uniqueData, }); - const { userId, user } = await ctx.modules.users.authenticateToken({ + const { userId, user } = await ctx.modules.users.authenticateTokenInternal({ userToken, fetchUser: true, }); diff --git a/modules/users/module.json b/modules/users/module.json index ec791d7c..3d733811 100644 --- a/modules/users/module.json +++ b/modules/users/module.json @@ -16,10 +16,10 @@ "tokens": {} }, "scripts": { - "fetch": { + "fetch_internal": { "name": "Fetch User" }, - "pub_fetch": { + "fetch": { "name": "Fetch User", "public": true }, @@ -29,11 +29,11 @@ "create": { "name": "Create User" }, - "authenticate_token": { + "authenticate_token_internal": { "name": "Authenticate User Token", "description": "Validate a user token. Throws an error if the token is invalid." }, - "pub_authenticate_token": { + "authenticate_token": { "name": "Public Authenticate User Token", "description": "Validate a user token. Throws an error if the token is invalid.", "public": true diff --git a/modules/users/scripts/authenticate_token.ts b/modules/users/scripts/authenticate_token.ts index 3e092c04..e8b59ada 100644 --- a/modules/users/scripts/authenticate_token.ts +++ b/modules/users/scripts/authenticate_token.ts @@ -16,6 +16,7 @@ export async function run( ctx: ScriptContext, req: Request, ): Promise { + await ctx.modules.rateLimit.throttlePublic({}); const { token } = await ctx.modules.tokens.validate({ token: req.userToken, diff --git a/modules/users/scripts/pub_authenticate_token.ts b/modules/users/scripts/authenticate_token_internal.ts similarity index 94% rename from modules/users/scripts/pub_authenticate_token.ts rename to modules/users/scripts/authenticate_token_internal.ts index e8b59ada..3e092c04 100644 --- a/modules/users/scripts/pub_authenticate_token.ts +++ b/modules/users/scripts/authenticate_token_internal.ts @@ -16,7 +16,6 @@ export async function run( ctx: ScriptContext, req: Request, ): Promise { - await ctx.modules.rateLimit.throttlePublic({}); const { token } = await ctx.modules.tokens.validate({ token: req.userToken, diff --git a/modules/users/scripts/fetch.ts b/modules/users/scripts/fetch.ts index 1f8445b9..5889d6c8 100644 --- a/modules/users/scripts/fetch.ts +++ b/modules/users/scripts/fetch.ts @@ -13,6 +13,7 @@ export async function run( ctx: ScriptContext, req: Request, ): Promise { + await ctx.modules.rateLimit.throttlePublic({}); const users = await ctx.db.query.users.findMany({ where: Query.inArray(Database.users.id, req.userIds), diff --git a/modules/users/scripts/pub_fetch.ts b/modules/users/scripts/fetch_internal.ts similarity index 90% rename from modules/users/scripts/pub_fetch.ts rename to modules/users/scripts/fetch_internal.ts index 5889d6c8..1f8445b9 100644 --- a/modules/users/scripts/pub_fetch.ts +++ b/modules/users/scripts/fetch_internal.ts @@ -13,7 +13,6 @@ export async function run( ctx: ScriptContext, req: Request, ): Promise { - await ctx.modules.rateLimit.throttlePublic({}); const users = await ctx.db.query.users.findMany({ where: Query.inArray(Database.users.id, req.userIds), diff --git a/modules/users/tests/e2e.ts b/modules/users/tests/e2e.ts index fda99841..9e95b68b 100644 --- a/modules/users/tests/e2e.ts +++ b/modules/users/tests/e2e.ts @@ -17,7 +17,7 @@ test("e2e", async (ctx: TestContext) => { userId: user.id, }); - const { userId } = await ctx.modules.users.authenticateToken({ + const { userId } = await ctx.modules.users.authenticateTokenInternal({ userToken: token.token, }); assertEquals(user.id, userId);