Skip to content

Commit

Permalink
chore: move users.authenticate_token and users.fetch to *_internal
Browse files Browse the repository at this point in the history
  • Loading branch information
ABCxFF committed Sep 27, 2024
1 parent 80763be commit 3789954
Show file tree
Hide file tree
Showing 27 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion modules/auth_email/scripts/verify_add_email_pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down
2 changes: 1 addition & 1 deletion modules/auth_email/scripts/verify_add_no_pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down
2 changes: 1 addition & 1 deletion modules/auth_email/scripts/verify_link_email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down
4 changes: 2 additions & 2 deletions modules/auth_email/tests/already_used.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -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,
});
Expand Down
2 changes: 1 addition & 1 deletion modules/auth_email/tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
4 changes: 2 additions & 2 deletions modules/auth_email/tests/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -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,
});
Expand Down
2 changes: 1 addition & 1 deletion modules/auth_email/utils/link_assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down
4 changes: 2 additions & 2 deletions modules/auth_username_password/tests/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down Expand Up @@ -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,
});

Expand Down
2 changes: 1 addition & 1 deletion modules/currency/scripts/fetch_balance_by_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function run(
): Promise<Response> {
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 });
Expand Down
2 changes: 1 addition & 1 deletion modules/friends/scripts/accept_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function run(
): Promise<Response> {
await ctx.modules.rateLimit.throttlePublic({ requests: 50 });

const { userId } = await ctx.modules.users.authenticateToken({
const { userId } = await ctx.modules.users.authenticateTokenInternal({
userToken: req.userToken,
});

Expand Down
2 changes: 1 addition & 1 deletion modules/friends/scripts/decline_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function run(
): Promise<Response> {
await ctx.modules.rateLimit.throttlePublic({ requests: 50 });

const { userId } = await ctx.modules.users.authenticateToken({
const { userId } = await ctx.modules.users.authenticateTokenInternal({
userToken: req.userToken,
});

Expand Down
2 changes: 1 addition & 1 deletion modules/friends/scripts/list_friends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function run(
): Promise<Response> {
await ctx.modules.rateLimit.throttlePublic({ requests: 50 });

const { userId } = await ctx.modules.users.authenticateToken({
const { userId } = await ctx.modules.users.authenticateTokenInternal({
userToken: req.userToken,
});

Expand Down
2 changes: 1 addition & 1 deletion modules/friends/scripts/list_incoming_friend_requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function run(
): Promise<Response> {
await ctx.modules.rateLimit.throttlePublic({ requests: 50 });

const { userId } = await ctx.modules.users.authenticateToken({
const { userId } = await ctx.modules.users.authenticateTokenInternal({
userToken: req.userToken,
});

Expand Down
2 changes: 1 addition & 1 deletion modules/friends/scripts/list_outgoing_friend_requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function run(
): Promise<Response> {
await ctx.modules.rateLimit.throttlePublic({});

const { userId } = await ctx.modules.users.authenticateToken({
const { userId } = await ctx.modules.users.authenticateTokenInternal({
userToken: req.userToken,
});

Expand Down
2 changes: 1 addition & 1 deletion modules/friends/scripts/remove_friend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function run(
): Promise<Response> {
await ctx.modules.rateLimit.throttlePublic({ requests: 50 });

const { userId } = await ctx.modules.users.authenticateToken({
const { userId } = await ctx.modules.users.authenticateTokenInternal({
userToken: req.userToken,
});

Expand Down
2 changes: 1 addition & 1 deletion modules/friends/scripts/send_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function run(
): Promise<Response> {
await ctx.modules.rateLimit.throttlePublic({});

const { userId } = await ctx.modules.users.authenticateToken({
const { userId } = await ctx.modules.users.authenticateTokenInternal({
userToken: req.userToken,
});

Expand Down
2 changes: 1 addition & 1 deletion modules/identities/scripts/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function run(
req: Request,
): Promise<Response> {
// 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({
Expand Down
2 changes: 1 addition & 1 deletion modules/identities/scripts/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function run(
): Promise<Response> {

// 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
Expand Down
2 changes: 1 addition & 1 deletion modules/identities/scripts/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion modules/identities/scripts/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function run(
req: Request,
): Promise<Response> {
// 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
Expand Down
4 changes: 2 additions & 2 deletions modules/identities/tests/sign_up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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,
});
Expand Down
8 changes: 4 additions & 4 deletions modules/users/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"tokens": {}
},
"scripts": {
"fetch": {
"fetch_internal": {
"name": "Fetch User"
},
"pub_fetch": {
"fetch": {
"name": "Fetch User",
"public": true
},
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules/users/scripts/authenticate_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function run(
ctx: ScriptContext,
req: Request,
): Promise<Response> {
await ctx.modules.rateLimit.throttlePublic({});

const { token } = await ctx.modules.tokens.validate({
token: req.userToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export async function run(
ctx: ScriptContext,
req: Request,
): Promise<Response> {
await ctx.modules.rateLimit.throttlePublic({});

const { token } = await ctx.modules.tokens.validate({
token: req.userToken,
Expand Down
1 change: 1 addition & 0 deletions modules/users/scripts/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export async function run(
ctx: ScriptContext,
req: Request,
): Promise<Response> {
await ctx.modules.rateLimit.throttlePublic({});

const users = await ctx.db.query.users.findMany({
where: Query.inArray(Database.users.id, req.userIds),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export async function run(
ctx: ScriptContext,
req: Request,
): Promise<Response> {
await ctx.modules.rateLimit.throttlePublic({});

const users = await ctx.db.query.users.findMany({
where: Query.inArray(Database.users.id, req.userIds),
Expand Down
2 changes: 1 addition & 1 deletion modules/users/tests/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3789954

Please sign in to comment.