feat: Introduce generic auth steps

This commit is contained in:
Ali BARIN
2021-10-14 18:34:30 +02:00
parent 1fbc58e7e1
commit 9c529b6c6d
12 changed files with 399 additions and 313 deletions

View File

@@ -1,15 +1,15 @@
import { GraphQLNonNull, GraphQLInt } from 'graphql';
import { GraphQLNonNull, GraphQLString } from 'graphql';
import Credential from '../../models/credential';
import authLinkType from '../types/auth-link';
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
type Params = {
credentialId: number,
id: number,
}
const createAuthLinkResolver = async (params: Params, req: RequestWithCurrentUser) => {
const credential = await Credential.query().findOne({
user_id: req.currentUser.id,
id: params.credentialId
id: params.id
})
const appClass = (await import(`../../apps/${credential.key}`)).default;
@@ -23,7 +23,7 @@ const createAuthLinkResolver = async (params: Params, req: RequestWithCurrentUse
const createAuthLink = {
type: authLinkType,
args: {
credentialId: { type: GraphQLNonNull(GraphQLInt) },
id: { type: GraphQLNonNull(GraphQLString) },
},
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => createAuthLinkResolver(params, req)
};