From 17921cf2211b4fa4b3998eb70c302f838862450c Mon Sep 17 00:00:00 2001 From: Samuel Andert Date: Tue, 22 Aug 2023 10:34:27 +0200 Subject: [PATCH] added token loading from env vars --- .meshrc.yml | 14 +++++++------- package.json | 4 +++- src/envelopePlugin.ts | 5 ++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.meshrc.yml b/.meshrc.yml index 76dcb6a..ea6d1b1 100644 --- a/.meshrc.yml +++ b/.meshrc.yml @@ -16,10 +16,10 @@ sources: source: schemas/directus.graphql operationHeaders: Authorization: Bearer {env.DIRECTUS_API} - # - name: Cloudron - # handler: - # openapi: - # endpoint: https://my.andert.me/api/v1 - # source: schemas/cloudron.json - # operationHeaders: - # Authorization: Bearer {env.CLOUDRON_API} + - name: Cloudron + handler: + openapi: + endpoint: https://my.andert.me/api/v1 + source: schemas/cloudron.json + operationHeaders: + Authorization: Bearer {env.CLOUDRON_API} diff --git a/package.json b/package.json index 7b8eb67..c3f9286 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,9 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "mesh build && next dev", + "mesh:dev": "dotenv -e .env.local -- mesh build", + "next:dev": "dotenv -e .env.local -- next dev", + "dev": "npm run mesh:dev && npm run next:dev", "schema": "dotenv -- node ./src/fetch-schema.js", "build": "mesh build && next build", "start": "next start", diff --git a/src/envelopePlugin.ts b/src/envelopePlugin.ts index 65bca36..3201def 100644 --- a/src/envelopePlugin.ts +++ b/src/envelopePlugin.ts @@ -7,12 +7,11 @@ type UserType = { const resolveUserFn = async context => { const authHeader = context.req.headers.authorization; - if (authHeader !== "token123") { + const authtoken = process.env.GRAPHQL_MESH + if (authHeader !== authtoken) { console.error('Failed to validate token') return null } - // If the token is valid, return the user - // Replace this with your actual user fetching logic return { id: 'user1' }; }