Skip to content

Commit

Permalink
fix: Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Oct 12, 2023
1 parent 050878f commit 166fa8e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
16 changes: 2 additions & 14 deletions api.planx.uk/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ import { userContext } from "../modules/auth/middleware";
import { ServerError } from "../errors";
import { buildJWTForAPIRole } from "../modules/auth/service";

/**
* @deprecated This client's permissions set are higher than required.
* Should only be used by trusted service-to-service calls (e.g Hasura -> API).
* Calls made by users should be directed through $public or the role-scoped getClient().
*
* Consider removing this and replacing with an "api" role using "backend-only" operations in Hasura
*/
export const $admin = new CoreDomainClient({
auth: { adminSecret: process.env.HASURA_GRAPHQL_ADMIN_SECRET! },
targetURL: process.env.HASURA_GRAPHQL_URL!,
});

/**
* Connects to Hasura using the "api" role
*
Expand Down Expand Up @@ -48,12 +36,12 @@ export const getClient = () => {
message: "Missing user context",
});

const client = new CoreDomainClient({
const $client = new CoreDomainClient({
targetURL: process.env.HASURA_GRAPHQL_URL!,
auth: {
jwt: store.user.jwt,
},
});

return client;
return $client;
};
5 changes: 2 additions & 3 deletions api.planx.uk/modules/auth/service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { sign } from "jsonwebtoken";
import { $admin } from "../../client";
import { $api } from "../../client";
import { User, Role } from "@opensystemslab/planx-core/types";

export const buildJWT = async (email: string): Promise<string | undefined> => {
// TODO: 🐓 🥚
const user = await $admin.user.getByEmail(email);
const user = await $api.user.getByEmail(email);
if (!user) return;

const data = {
Expand Down

0 comments on commit 166fa8e

Please sign in to comment.