Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 01d9791

Browse files
authored
chore!: rename scripts get -> fetch (#113)
feat(users): optionally return `user` in `authenticate_token`
1 parent c9e0f72 commit 01d9791

28 files changed

+81
-2810
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
- push
44

55
env:
6-
CURRENT_WORKING_ENGINE_REF: main
6+
OPENGB_REF: "a15d4191665738f20d5761ab46f4c649f9150289"
77

88
jobs:
99
build:
@@ -18,6 +18,7 @@ jobs:
1818
- name: Checkout opengb
1919
uses: actions/checkout@v4
2020
with:
21+
ref: ${{ env.OPENGB_REF }}
2122
repository: rivet-gg/opengb
2223
path: opengb
2324

modules/auth/module.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
"rate_limit": {}
1919
},
2020
"scripts": {
21-
"auth_email_passwordless": {
22-
"name": "Authenticate Email Passwordless",
21+
"send_email_verification": {
22+
"name": "Send Email Verification",
2323
"description": "Send a one-time verification code to a user's email address to authenticate them.",
2424
"public": true
2525
},
26-
"verify_email_passwordless": {
27-
"name": "Verify Email Passwordless",
26+
"complete_email_verification": {
27+
"name": "Complete Email Verification",
2828
"description": "Verify a user's email address with a one-time verification code.",
2929
"public": true
3030
}
@@ -49,4 +49,4 @@
4949
"name": "Email Already Used"
5050
}
5151
}
52-
}
52+
}

modules/auth/scripts/verify_email_passwordless.ts renamed to modules/auth/scripts/complete_email_verification.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function run(
8080
if (verification.userId) {
8181
userId = verification.userId;
8282
} else {
83-
const { user } = await ctx.modules.users.createUser({});
83+
const { user } = await ctx.modules.users.create({});
8484
userId = user.id;
8585
}
8686

@@ -100,7 +100,7 @@ export async function run(
100100
assertExists(userId);
101101

102102
// Create token
103-
const { token } = await ctx.modules.users.createUserToken({ userId });
103+
const { token } = await ctx.modules.users.createToken({ userId });
104104

105105
return { token };
106106
}

modules/auth/scripts/auth_email_passwordless.ts renamed to modules/auth/scripts/send_email_verification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function run(
2828
let userId: string | undefined = existingIdentity?.userId;
2929

3030
if (req.userToken) {
31-
const authRes = await ctx.modules.users.authenticateUser({
31+
const authRes = await ctx.modules.users.authenticateToken({
3232
userToken: req.userToken,
3333
});
3434

modules/auth/tests/e2e.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import { faker } from "https://deno.land/x/deno_faker@v1.0.3/mod.ts";
44

55
test("e2e", async (ctx: TestContext) => {
66
// First we create a new user, and "register" into the auth
7-
// using an authEmailPasswordless({ email, userToken })
7+
// using an sendEmailVerification({ email, userToken })
88
// call
9-
const { user } = await ctx.modules.users.createUser({});
9+
const { user } = await ctx.modules.users.create({});
1010

11-
const { token: session } = await ctx.modules.users.createUserToken({
11+
const { token: session } = await ctx.modules.users.createToken({
1212
userId: user.id
1313
});
1414

1515
const fakeEmail = faker.internet.email();
1616

1717
// Now we test that post-signin, we get the same user
1818
{
19-
const authRes = await ctx.modules.auth.authEmailPasswordless({
19+
const authRes = await ctx.modules.auth.sendEmailVerification({
2020
email: fakeEmail,
2121
userToken: session.token
2222
});
@@ -30,7 +30,7 @@ test("e2e", async (ctx: TestContext) => {
3030

3131
// Now by verifying the email, we register, and can also use
3232
// this to verify the token
33-
const verifyRes = await ctx.modules.auth.verifyEmailPasswordless({
33+
const verifyRes = await ctx.modules.auth.completeEmailVerification({
3434
verificationId: authRes.verification.id,
3535
code: code,
3636
});
@@ -39,7 +39,7 @@ test("e2e", async (ctx: TestContext) => {
3939

4040

4141
// Make sure we end up with the same user we started with
42-
const verifyRes2 = await ctx.modules.users.authenticateUser({
42+
const verifyRes2 = await ctx.modules.users.authenticateToken({
4343
userToken: verifyRes.token.token
4444
});
4545

@@ -49,7 +49,7 @@ test("e2e", async (ctx: TestContext) => {
4949
// Now we try logging back in with the same email,
5050
// but without a token, expecting the same user
5151
{
52-
const authRes = await ctx.modules.auth.authEmailPasswordless({
52+
const authRes = await ctx.modules.auth.sendEmailVerification({
5353
email: fakeEmail
5454
});
5555

@@ -60,12 +60,12 @@ test("e2e", async (ctx: TestContext) => {
6060
},
6161
});
6262

63-
const verifyRes = await ctx.modules.auth.verifyEmailPasswordless({
63+
const verifyRes = await ctx.modules.auth.completeEmailVerification({
6464
verificationId: authRes.verification.id,
6565
code: code,
6666
});
6767

68-
const verifyRes2 = await ctx.modules.users.authenticateUser({
68+
const verifyRes2 = await ctx.modules.users.authenticateToken({
6969
userToken: verifyRes.token.token
7070
});
7171

modules/currency/scripts/get_balance_by_token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function run(
1515
): Promise<Response> {
1616
await ctx.modules.rateLimit.throttlePublic({ requests: 25 });
1717

18-
const { userId } = await ctx.modules.users.authenticateUser({
18+
const { userId } = await ctx.modules.users.authenticateToken({
1919
userToken: req.userToken,
2020
});
2121
const { balance } = await ctx.modules.currency.getBalance({ userId });

modules/currency/tests/e2e.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { faker } from "https://deno.land/x/deno_faker@v1.0.3/mod.ts";
55
test(
66
"e2e transaction",
77
async (ctx: TestContext) => {
8-
const { user: user } = await ctx.modules.users.createUser({
8+
const { user: user } = await ctx.modules.users.create({
99
username: faker.internet.userName(),
1010
});
11-
const { token } = await ctx.modules.users.createUserToken({
11+
const { token } = await ctx.modules.users.createToken({
1212
userId: user.id,
1313
});
1414

modules/currency/tests/errors.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test(
1919
test(
2020
"withdraw more than balance",
2121
async (ctx: TestContext) => {
22-
const { user: user } = await ctx.modules.users.createUser({
22+
const { user: user } = await ctx.modules.users.create({
2323
username: faker.internet.userName(),
2424
});
2525

@@ -38,7 +38,7 @@ test(
3838
test(
3939
"withdraw negative amount",
4040
async (ctx: TestContext) => {
41-
const { user: user } = await ctx.modules.users.createUser({
41+
const { user: user } = await ctx.modules.users.create({
4242
username: faker.internet.userName(),
4343
});
4444

@@ -52,7 +52,7 @@ test(
5252
test(
5353
"withdraw Infinity",
5454
async (ctx: TestContext) => {
55-
const { user: user } = await ctx.modules.users.createUser({
55+
const { user: user } = await ctx.modules.users.create({
5656
username: faker.internet.userName(),
5757
});
5858

@@ -69,7 +69,7 @@ test(
6969
test(
7070
"withdraw NaN",
7171
async (ctx: TestContext) => {
72-
const { user: user } = await ctx.modules.users.createUser({
72+
const { user: user } = await ctx.modules.users.create({
7373
username: faker.internet.userName(),
7474
});
7575

@@ -83,7 +83,7 @@ test(
8383
test(
8484
"deposit Infinity",
8585
async (ctx: TestContext) => {
86-
const { user: user } = await ctx.modules.users.createUser({
86+
const { user: user } = await ctx.modules.users.create({
8787
username: faker.internet.userName(),
8888
});
8989

@@ -97,7 +97,7 @@ test(
9797
test(
9898
"deposit NaN",
9999
async (ctx: TestContext) => {
100-
const { user: user } = await ctx.modules.users.createUser({
100+
const { user: user } = await ctx.modules.users.create({
101101
username: faker.internet.userName(),
102102
});
103103

@@ -111,7 +111,7 @@ test(
111111
test(
112112
"deposit negative amount",
113113
async (ctx: TestContext) => {
114-
const { user: user } = await ctx.modules.users.createUser({
114+
const { user: user } = await ctx.modules.users.create({
115115
username: faker.internet.userName(),
116116
});
117117

@@ -125,7 +125,7 @@ test(
125125
test(
126126
"set balance to negative",
127127
async (ctx: TestContext) => {
128-
const { user: user } = await ctx.modules.users.createUser({
128+
const { user: user } = await ctx.modules.users.create({
129129
username: faker.internet.userName(),
130130
});
131131

@@ -139,7 +139,7 @@ test(
139139
test(
140140
"set balance to NaN",
141141
async (ctx: TestContext) => {
142-
const { user: user } = await ctx.modules.users.createUser({
142+
const { user: user } = await ctx.modules.users.create({
143143
username: faker.internet.userName(),
144144
});
145145

@@ -154,7 +154,7 @@ test(
154154
test(
155155
"set balance to infinity",
156156
async (ctx: TestContext) => {
157-
const { user: user } = await ctx.modules.users.createUser({
157+
const { user: user } = await ctx.modules.users.create({
158158
username: faker.internet.userName(),
159159
});
160160

modules/friends/scripts/accept_request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function run(
1313
): Promise<Response> {
1414
await ctx.modules.rateLimit.throttlePublic({ requests: 50 });
1515

16-
const { userId } = await ctx.modules.users.authenticateUser({
16+
const { userId } = await ctx.modules.users.authenticateToken({
1717
userToken: req.userToken,
1818
});
1919

modules/friends/scripts/decline_request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export async function run(
1616
): Promise<Response> {
1717
await ctx.modules.rateLimit.throttlePublic({ requests: 50 });
1818

19-
const { userId } = await ctx.modules.users.authenticateUser({
19+
const { userId } = await ctx.modules.users.authenticateToken({
2020
userToken: req.userToken,
2121
});
2222

0 commit comments

Comments
 (0)