Skip to content

Public Queries #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4535618
refactor(env): rename Polar sandbox switch
coopbri Apr 25, 2025
5d7ba93
chore: update import order
coopbri Apr 25, 2025
0345d99
chore: add TODO
coopbri Apr 25, 2025
4587fa1
chore(cors): set prerelease URL
coopbri Apr 25, 2025
441d061
fix(plugins): allow users to delete their own members records
hobbescodes Apr 29, 2025
fed3177
docs(readme): update README
coopbri Apr 30, 2025
01135e8
refactor(plugins): update mode for useAuth
hobbescodes May 1, 2025
2e6797f
Merge branch 'feature/prerelease' into feature/public-queries
hobbescodes May 1, 2025
d3e20de
Merge branch 'master' into feature/public-queries
hobbescodes May 2, 2025
d4f0921
Merge branch 'master' into feature/public-queries
hobbescodes May 6, 2025
f75fc8b
refactor(plugins): update RBAC plugins to handle all mutation scopes
hobbescodes May 7, 2025
1a2d5d7
refactor(plugins): update user RBAC plugin to handle all mutation scopes
hobbescodes May 7, 2025
41ebf38
refactor(tags): move create user control to tags as it can be complet…
hobbescodes May 7, 2025
931035b
Merge branch 'master' into feature/public-queries
hobbescodes May 14, 2025
39865a6
refactor(plugins): remove thrown error from useAuth
hobbescodes May 15, 2025
81bdc88
Merge branch 'master' into feature/public-queries
hobbescodes May 15, 2025
6d8ecd1
fix: update downvote plugin
hobbescodes May 15, 2025
4e76343
fix: update downvote plugin
hobbescodes May 15, 2025
5d28d27
Merge branch 'master' into feature/public-queries
hobbescodes May 16, 2025
b772645
Merge branch 'master' into feature/public-queries
hobbescodes May 20, 2025
4556dd9
Merge branch 'master' into feature/public-queries
hobbescodes May 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ AUTH_BASE_URL="https://localhost:8000/api/auth"

CHECKOUT_SUCCESS_URL="https://localhost:3000/confirmation"

# Define whether to connect to Polar's `sandbox` environment
SANDBOX="true"
# whether to connect to Polar's sandbox environment (https://docs.polar.sh/integrate/sandbox)
ENABLE_POLAR_SANDBOX="true"
30 changes: 15 additions & 15 deletions src/generated/graphql/schema.executable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const spec_downvote = {
},
description: undefined,
extensions: {
oid: "216526",
oid: "219066",
isTableLike: true,
pg: {
serviceName: "main",
Expand Down Expand Up @@ -237,7 +237,7 @@ const spec_upvote = {
},
description: undefined,
extensions: {
oid: "216439",
oid: "218979",
isTableLike: true,
pg: {
serviceName: "main",
Expand Down Expand Up @@ -320,7 +320,7 @@ const spec_invitation = {
},
description: undefined,
extensions: {
oid: "216625",
oid: "219165",
isTableLike: true,
pg: {
serviceName: "main",
Expand Down Expand Up @@ -403,7 +403,7 @@ const spec_organization = {
},
description: undefined,
extensions: {
oid: "216401",
oid: "218941",
isTableLike: true,
pg: {
serviceName: "main",
Expand Down Expand Up @@ -498,7 +498,7 @@ const spec_comment = {
},
description: undefined,
extensions: {
oid: "216506",
oid: "219046",
isTableLike: true,
pg: {
serviceName: "main",
Expand Down Expand Up @@ -617,7 +617,7 @@ const spec_project = {
},
description: undefined,
extensions: {
oid: "216425",
oid: "218965",
isTableLike: true,
pg: {
serviceName: "main",
Expand All @@ -638,7 +638,7 @@ const roleCodec = enumCodec({
values: ["owner", "admin", "member"],
description: undefined,
extensions: {
oid: "216545",
oid: "219085",
pg: {
serviceName: "main",
schemaName: "public",
Expand Down Expand Up @@ -717,7 +717,7 @@ const spec_member = {
},
description: undefined,
extensions: {
oid: "216461",
oid: "219001",
isTableLike: true,
pg: {
serviceName: "main",
Expand Down Expand Up @@ -848,7 +848,7 @@ const spec_post = {
},
description: undefined,
extensions: {
oid: "216415",
oid: "218955",
isTableLike: true,
pg: {
serviceName: "main",
Expand Down Expand Up @@ -967,7 +967,7 @@ const spec_postStatus = {
},
description: undefined,
extensions: {
oid: "216599",
oid: "219139",
isTableLike: true,
pg: {
serviceName: "main",
Expand All @@ -988,7 +988,7 @@ const tierCodec = enumCodec({
values: ["basic", "team", "enterprise"],
description: undefined,
extensions: {
oid: "216648",
oid: "219188",
pg: {
serviceName: "main",
schemaName: "public",
Expand Down Expand Up @@ -1117,7 +1117,7 @@ const spec_user = {
},
description: undefined,
extensions: {
oid: "216449",
oid: "218989",
isTableLike: true,
pg: {
serviceName: "main",
Expand Down Expand Up @@ -4082,7 +4082,7 @@ const planWrapper3 = (plan, _, fieldArgs) => {
}).from(members).where(and(eq(members.userId, currentUser.id), eq(members.organizationId, member.organizationId)));
if (userRole.role !== "owner") throw new Error("Insufficient permissions");
if (patch.role === "owner") throw new Error("Organizations can only have one owner");
} else throw new Error("Insufficient permissions");
} else if ("create" === "update") throw new Error("Insufficient permissions");
}
});
return plan();
Expand Down Expand Up @@ -4306,7 +4306,7 @@ const planWrapper10 = (plan, _, fieldArgs) => {
}).from(members).where(and(eq(members.userId, currentUser.id), eq(members.organizationId, member.organizationId)));
if (userRole.role !== "owner") throw new Error("Insufficient permissions");
if (patch.role === "owner") throw new Error("Organizations can only have one owner");
} else throw new Error("Insufficient permissions");
} else if ("update" === "update") throw new Error("Insufficient permissions");
}
});
return plan();
Expand Down Expand Up @@ -4583,7 +4583,7 @@ const planWrapper19 = (plan, _, fieldArgs) => {
}).from(members).where(and(eq(members.userId, currentUser.id), eq(members.organizationId, member.organizationId)));
if (userRole.role !== "owner") throw new Error("Insufficient permissions");
if (patch.role === "owner") throw new Error("Organizations can only have one owner");
} else throw new Error("Insufficient permissions");
} else if ("delete" === "update") throw new Error("Insufficient permissions");
}
});
return plan();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/config/env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export const {
POLAR_WEBHOOK_SECRET,
CHECKOUT_SUCCESS_URL,
AUTH_BASE_URL,
SANDBOX,
ENABLE_POLAR_SANDBOX,
} = process.env;

export const isDevEnv = NODE_ENV === "development";
export const isProdEnv = NODE_ENV === "production";
export const isSandbox = SANDBOX === "true";
export const enablePolarSandbox = ENABLE_POLAR_SANDBOX === "true";
4 changes: 2 additions & 2 deletions src/lib/plugins/envelop/useAuth.plugin.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont know if we really need to ever throw here anymore, but rather just early return null. The null will be used for the RBAC plugins and be caught to protect the mutations.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const resolveUser: ResolveUserFn<SelectUser, GraphQLContext> = async (
.get("authorization")
?.split("Bearer ")[1];

if (!accessToken) throw new Error("Invalid or missing access token");
if (!accessToken) return null;

// TODO validate access token (introspection endpoint?) here?

Expand Down Expand Up @@ -75,7 +75,7 @@ const resolveUser: ResolveUserFn<SelectUser, GraphQLContext> = async (
const useAuth = () =>
useGenericAuth({
resolveUserFn: resolveUser,
mode: "protect-all",
mode: "resolve-only",
});

export default useAuth;
14 changes: 8 additions & 6 deletions src/lib/plugins/postgraphile/MemberRBAC.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ const validatePermissions = (propName: string, scope: MutationScope) =>
throw new Error("Organizations can only have one owner");
}
} else {
// Restrict current users from updating their own role
throw new Error("Insufficient permissions");
if (scope === "update") {
// Restrict current users from updating their own role
throw new Error("Insufficient permissions");

// TODO: replace above with below when ownership transfers are allowed
// if (scope === "update" && member.role !== "owner") {
// throw new Error("Insufficient permissions");
// }
// TODO: replace above with below when ownership transfers are allowed
// if (scope === "update" && member.role !== "owner") {
// throw new Error("Insufficient permissions");
// }
}
}
}
},
Expand Down
9 changes: 5 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
POLAR_WEBHOOK_SECRET,
PORT,
SKIP_AUTH,
enablePolarSandbox,
isDevEnv,
isProdEnv,
isSandbox,
} from "lib/config/env.config";
import { dbPool as db } from "lib/db/db";
import { users } from "lib/drizzle/schema";
Expand Down Expand Up @@ -82,7 +82,8 @@ app.use(
// enable CORS
cors({
origin: isProdEnv
? [appConfig.url, "https://backfeed-app-prerelease.up.railway.app"]
? // TODO remove prerelease URL once ready
[appConfig.url, "https://backfeed-prerelease.omni.dev"]
: "https://localhost:3000",
credentials: true,
allowMethods: ["GET", "POST"],
Expand All @@ -94,7 +95,7 @@ app.get(
Checkout({
accessToken: POLAR_ACCESS_TOKEN,
successUrl: CHECKOUT_SUCCESS_URL,
server: isSandbox ? "sandbox" : "production",
server: enablePolarSandbox ? "sandbox" : "production",
}),
);

Expand All @@ -108,7 +109,7 @@ app.get(

return customerId;
},
server: isSandbox ? "sandbox" : "production",
server: enablePolarSandbox ? "sandbox" : "production",
}),
);

Expand Down