mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
try to login user
This commit is contained in:
parent
c2ecd0d641
commit
8e96aa02df
@ -16,12 +16,14 @@
|
||||
"express": "^4.17.1",
|
||||
"express-graphql": "^0.12.0",
|
||||
"graphql": "^15.5.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"type-graphql": "^1.1.1",
|
||||
"typeorm": "^0.2.34"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.12",
|
||||
"@types/jsonwebtoken": "^8.5.2",
|
||||
"@typescript-eslint/eslint-plugin": "^4.28.0",
|
||||
"@typescript-eslint/parser": "^4.28.0",
|
||||
"eslint": "^7.29.0",
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import axios from 'axios'
|
||||
import { graphql } from 'graphql'
|
||||
import CONFIG from '../config'
|
||||
import { User } from '../graphql/models/User'
|
||||
import { LoginUserInput } from '../graphql/inputs/LoginUserInput'
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
// import regeneratorRuntime from 'regenerator-runtime'
|
||||
|
||||
@ -51,13 +54,19 @@ interface NetworkInfosResult {
|
||||
}
|
||||
}
|
||||
|
||||
interface LoginResult {
|
||||
state: string
|
||||
msg?: string
|
||||
details?: number
|
||||
info?: string
|
||||
user?: User
|
||||
// eslint-disable-next-line camelcase
|
||||
session_id?: number
|
||||
}
|
||||
|
||||
const loginAPI = {
|
||||
login: async (email: string, password: string): Promise<any> => {
|
||||
const payload: any = {
|
||||
email,
|
||||
password,
|
||||
}
|
||||
return apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', payload)
|
||||
login: async (login: LoginUserInput): Promise<LoginResult> => {
|
||||
return (await apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', login)).result.data
|
||||
},
|
||||
logout: async (sessionId: number): Promise<any> => {
|
||||
const payload: any = { session_id: sessionId }
|
||||
@ -172,4 +181,4 @@ const loginAPI = {
|
||||
},
|
||||
}
|
||||
|
||||
export { loginAPI, NetworkInfosResult }
|
||||
export { loginAPI, NetworkInfosResult, LoginResult }
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import { Resolver, Query, Mutation, Arg } from 'type-graphql'
|
||||
import { User } from '../models/User'
|
||||
import jwt from 'jsonwebtoken'
|
||||
import { LoginUserInput } from '../inputs/LoginUserInput'
|
||||
import { loginAPI, LoginResult } from '../../apis/loginAPI'
|
||||
// import { CreateBookInput } from '../inputs/CreateBookInput'
|
||||
// import { UpdateBookInput } from '../inputs/UpdateBookInput'
|
||||
|
||||
@ -15,6 +18,12 @@ export class UserResolver {
|
||||
return User.findOne({ where: { id } })
|
||||
}
|
||||
|
||||
@Mutation(() => User)
|
||||
async login(@Arg('data') data: LoginUserInput): Promise<User> {
|
||||
const loginResult: LoginResult = await loginAPI.login(data)
|
||||
return loginResult.user ? loginResult.user : new User()
|
||||
}
|
||||
|
||||
/*
|
||||
@Mutation(() => User)
|
||||
async createBook(@Arg('data') data: CreateBookInput) {
|
||||
|
||||
@ -10,7 +10,7 @@ import { GroupResolver } from './graphql/resolvers/GroupResolver'
|
||||
|
||||
async function main() {
|
||||
// const connection = await createConnection()
|
||||
const schema = await buildSchema({ resolvers: [BookResolver, GroupResolver] })
|
||||
const schema = await buildSchema({ resolvers: [BookResolver, GroupResolver, UserResolver] })
|
||||
const server = express()
|
||||
|
||||
server.use(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user