middleware for register a new user

This commit is contained in:
Moriz Wahl 2021-08-30 19:46:20 +02:00
parent 0ef60ab92c
commit c7d044b532
3 changed files with 16 additions and 5 deletions

View File

@ -1,5 +1,5 @@
// import jwt from 'jsonwebtoken'
import { Resolver, Query, Args, Arg } from 'type-graphql'
import { Resolver, Query, Args, Arg, UseMiddleware } from 'type-graphql'
import CONFIG from '../../config'
import { CheckUsernameResponse } from '../models/CheckUsernameResponse'
import { LoginResponse } from '../models/LoginResponse'
@ -15,6 +15,7 @@ import {
} from '../inputs/LoginUserInput'
import { apiPost, apiGet } from '../../apis/HttpRequest'
import { KlicktippConnector } from '../../apis/klicktippAPI'
import { registerMiddleware } from '../../middleware/registerMiddleware'
@Resolver()
export class UserResolver {
@ -73,6 +74,7 @@ export class UserResolver {
}
@Query(() => String)
@UseMiddleware(registerMiddleware)
async create(
@Args() { email, firstName, lastName, password, language }: CreateUserArgs,
): Promise<string> {
@ -94,11 +96,12 @@ export class UserResolver {
// CONFIG.KLICKTIPP_PASSWORD,
// )
// if (loginSuccessful) {
const fields = {}
const apiKey = language === 'de' ? CONFIG.KLICKTIPP_APIKEY_DE : CONFIG.KLICKTIPP_APIKEY_EN
await this.connector.signin(apiKey, email, fields)
// const fields = {}
// const apiKey = language === 'de' ? CONFIG.KLICKTIPP_APIKEY_DE : CONFIG.KLICKTIPP_APIKEY_EN
// await this.connector.signin(apiKey, email, fields)
// }
// I think we need something more than success here to process the returned data in the middleware
return 'success'
}

View File

@ -0,0 +1,8 @@
import { MiddlewareFn } from 'type-graphql'
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
export const registerMiddleware: MiddlewareFn = async ({ root, args, context, info }, next) => {
const result = await next()
// do something here
return result
}

View File

@ -4,7 +4,7 @@
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */