Skip to content

Commit 282fc4e

Browse files
authored
Better namespace env variables (#41)
1 parent 8e100ea commit 282fc4e

File tree

13 files changed

+44
-38
lines changed

13 files changed

+44
-38
lines changed

examples/bun-api/main.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { AdminApi, UserApi } from "@userhub/sdk";
22

3-
const adminKey = process.env.ADMIN_KEY || "";
3+
const adminKey = process.env.USERHUB_ADMIN_KEY || "";
44
if (!adminKey) {
5-
console.error("ADMIN_KEY required");
5+
console.error("USERHUB_ADMIN_KEY required");
66
process.exit(1);
77
}
88

9-
const userKey = process.env.USER_KEY || "";
9+
const userKey = process.env.USERHUB_USER_KEY || "";
1010
if (!userKey) {
11-
console.error("USER_KEY required");
11+
console.error("USERHUB_USER_KEY required");
1212
process.exit(1);
1313
}
1414

examples/bun-webhook/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { Webhook } from "@userhub/sdk";
22

33
const port = process.env.PORT || "8000";
44

5-
const signingSecret = process.env.SIGNING_SECRET;
5+
const signingSecret = process.env.USERHUB_SIGNING_SECRET;
66
if (!signingSecret) {
7-
console.error("SIGNING_SECRET required");
7+
console.error("USERHUB_SIGNING_SECRET required");
88
process.exit(1);
99
}
1010

examples/deno-api/main.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { AdminApi, UserApi } from "https://deno.land/x/userhub_sdk/mod.ts";
22

3-
const adminKey = Deno.env.get("ADMIN_KEY") || "";
3+
const adminKey = Deno.env.get("USERHUB_ADMIN_KEY") || "";
44
if (!adminKey) {
5-
console.error("ADMIN_KEY required");
5+
console.error("USERHUB_ADMIN_KEY required");
66
Deno.exit(1);
77
}
88

9-
const userKey = Deno.env.get("USER_KEY") || "";
9+
const userKey = Deno.env.get("USERHUB_USER_KEY") || "";
1010
if (!userKey) {
11-
console.error("USER_KEY required");
11+
console.error("USERHUB_USER_KEY required");
1212
Deno.exit(1);
1313
}
1414

examples/deno-webhook/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { Webhook } from "https://deno.land/x/userhub_sdk/mod.ts";
22

33
const port = parseInt(Deno.env.get("PORT") || "8000", 10);
44

5-
const signingSecret = Deno.env.get("SIGNING_SECRET") || "";
5+
const signingSecret = Deno.env.get("USERHUB_SIGNING_SECRET") || "";
66
if (!signingSecret) {
7-
console.error("SIGNING_SECRET required");
7+
console.error("USERHUB_SIGNING_SECRET required");
88
Deno.exit(1);
99
}
1010

examples/express-webhook/main.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import express from "express";
33

44
const port = process.env.PORT || "8000";
55

6-
const signingSecret = process.env.SIGNING_SECRET;
6+
const signingSecret = process.env.USERHUB_SIGNING_SECRET;
77
if (!signingSecret) {
8-
console.error("SIGNING_SECRET required");
8+
console.error("USERHUB_SIGNING_SECRET required");
99
process.exit(1);
1010
}
1111

examples/nextjs-app-webhook/app/webhook/route.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Webhook, WebhookRequest } from "@userhub/sdk";
22

33
export async function POST(req) {
4-
const signingSecret = process.env.SIGNING_SECRET;
4+
const signingSecret = process.env.USERHUB_SIGNING_SECRET;
55
if (!signingSecret) {
6-
throw new Error("SIGNING_SECRET required");
6+
throw new Error("USERHUB_SIGNING_SECRET required");
77
}
88

99
const webhook = new Webhook(signingSecret);

examples/nextjs-pages-webhook/pages/api/webhook.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export const config = {
77
};
88

99
export default async function (req, res) {
10-
const signingSecret = process.env.SIGNING_SECRET;
10+
const signingSecret = process.env.USERHUB_SIGNING_SECRET;
1111
if (!signingSecret) {
12-
throw new Error("SIGNING_SECRET required");
12+
throw new Error("USERHUB_SIGNING_SECRET required");
1313
}
1414

1515
const webhook = new Webhook(signingSecret);

examples/node-api/main.mjs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { AdminApi, UserApi } from "@userhub/sdk";
22

3-
const adminKey = process.env.ADMIN_KEY;
3+
const adminKey = process.env.USERHUB_ADMIN_KEY;
44
if (!adminKey) {
5-
console.error("ADMIN_KEY required");
5+
console.error("USERHUB_ADMIN_KEY required");
66
process.exit(1);
77
}
88

9-
const userKey = process.env.USER_KEY;
9+
const userKey = process.env.USERHUB_USER_KEY;
1010
if (!userKey) {
11-
console.error("USER_KEY required");
11+
console.error("USERHUB_USER_KEY required");
1212
process.exit(1);
1313
}
1414

examples/node-webhook/main.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { createServer } from "http";
33

44
const port = process.env.PORT || "8000";
55

6-
const signingSecret = process.env.SIGNING_SECRET;
6+
const signingSecret = process.env.USERHUB_SIGNING_SECRET;
77
if (!signingSecret) {
8-
console.error("SIGNING_SECRET required");
8+
console.error("USERHUB_SIGNING_SECRET required");
99
process.exit(1);
1010
}
1111

test/deno/basics_test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { jsonReviser } from "../../src/internal/util.ts";
22
import { AdminApi, UserApi, type adminv1 } from "../../src/mod.ts";
3-
import { ADMIN_KEY, USER_KEY } from "./util.ts";
3+
import { USERHUB_ADMIN_KEY, USERHUB_USER_KEY } from "./util.ts";
44
import {
55
assert,
66
assertEquals,
@@ -10,25 +10,25 @@ import {
1010
Deno.test({
1111
name: "Admin API",
1212
fn: async () => {
13-
const adminApi = new AdminApi(ADMIN_KEY);
13+
const adminApi = new AdminApi(USERHUB_ADMIN_KEY);
1414

1515
const res = await adminApi.users.list();
1616
assert(res);
1717
assertInstanceOf(res.users, Array);
1818
},
19-
ignore: !ADMIN_KEY,
19+
ignore: !USERHUB_ADMIN_KEY,
2020
});
2121

2222
Deno.test({
2323
name: "User API",
2424
fn: async () => {
25-
const userApi = new UserApi(USER_KEY);
25+
const userApi = new UserApi(USERHUB_USER_KEY);
2626

2727
const res = await userApi.session.get();
2828
assert(res);
2929
assertInstanceOf(res.scopes, Array);
3030
},
31-
ignore: !USER_KEY,
31+
ignore: !USERHUB_USER_KEY,
3232
});
3333

3434
Deno.test("Model", () => {

test/deno/util.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const ADMIN_KEY = Deno.env.get("TEST_ADMIN_KEY") || "";
2-
export const USER_KEY = Deno.env.get("TEST_USER_KEY") || "";
1+
export const USERHUB_ADMIN_KEY = Deno.env.get("TEST_USERHUB_ADMIN_KEY") || "";
2+
export const USERHUB_USER_KEY = Deno.env.get("TEST_USERHUB_USER_KEY") || "";
33
export const CI = !!Deno.env.get("CI");

test/node/basics.test.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@ import { jsonReviser } from "../../src/internal/util.ts";
33
import type { adminv1 } from "../../src/mod.ts";
44
import { AdminApi, Code, UserApi, UserHubError } from "../../src/mod.ts";
55
import { createTestServer } from "./test-server.ts";
6-
import { ADMIN_KEY, USER_KEY, testAdmin, testSlow, testUser } from "./util.ts";
6+
import {
7+
USERHUB_ADMIN_KEY,
8+
USERHUB_USER_KEY,
9+
testAdmin,
10+
testSlow,
11+
testUser,
12+
} from "./util.ts";
713
import { expect, test } from "vitest";
814

915
testAdmin("Admin API", async () => {
10-
const adminApi = new AdminApi(ADMIN_KEY);
16+
const adminApi = new AdminApi(USERHUB_ADMIN_KEY);
1117

1218
const res = await adminApi.users.list();
1319
expect(res).toBeTruthy();
1420
expect(res.users).instanceof(Array);
1521
});
1622

1723
testUser("User API", async () => {
18-
const userApi = new UserApi(USER_KEY);
24+
const userApi = new UserApi(USERHUB_USER_KEY);
1925

2026
const res = await userApi.session.get();
2127
expect(res).toBeTruthy();

test/node/util.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { test } from "vitest";
22

3-
export const ADMIN_KEY = process.env.TEST_ADMIN_KEY || "";
4-
export const USER_KEY = process.env.TEST_USER_KEY || "";
3+
export const USERHUB_ADMIN_KEY = process.env.TEST_USERHUB_ADMIN_KEY || "";
4+
export const USERHUB_USER_KEY = process.env.TEST_USERHUB_USER_KEY || "";
55
export const CI = !!process.env.CI;
66

7-
export const testAdmin = test.skipIf(!ADMIN_KEY);
8-
export const testUser = test.skipIf(!USER_KEY);
7+
export const testAdmin = test.skipIf(!USERHUB_ADMIN_KEY);
8+
export const testUser = test.skipIf(!USERHUB_USER_KEY);
99
export const testSlow = test.skipIf(!CI);

0 commit comments

Comments
 (0)