From 02588240f9333f57f18c20f4316d855709653783 Mon Sep 17 00:00:00 2001 From: Aashish <83752052+120EE0692@users.noreply.github.com> Date: Thu, 20 Oct 2022 22:37:35 +0530 Subject: [PATCH] feat: check permission util (#284) * chore: add jsonwebtoken * feat: add permission check * chore: use permissions as an array * chore: remove jsonwebtoken * feat: get verified permission * chore: remove console log --- client/src/utils/getAccess.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 client/src/utils/getAccess.js diff --git a/client/src/utils/getAccess.js b/client/src/utils/getAccess.js new file mode 100644 index 00000000..8b77114e --- /dev/null +++ b/client/src/utils/getAccess.js @@ -0,0 +1,27 @@ +import { parseCookies } from 'nookies'; + +export default async function getAccess(ctx, permissions) { + if (!ctx || !permissions) return false; + try { + const cookies = parseCookies(ctx); + const { data, error } = await fetch( + process.env.NODE_ENV === 'production' + ? 'https://mm.dashnet.in/api/auth/check' + : 'http://localhost:5000/auth/check', + { + method: 'GET', + mode: 'cors', + cache: 'no-cache', + headers: { + authorization: cookies.firebaseToken, + }, + }, + ); + if (error) { + throw error; + } + return data; + } catch (error) { + throw error; + } +}