Files
prism/backend/src/modules/auth/auth.resolver.ts

34 lines
814 B
TypeScript

import { Resolver, Mutation, Args, ObjectType, Field } from '@nestjs/graphql';
import { AuthService } from './auth.service';
import { User } from '../users/entities/user.entity';
@ObjectType()
class AuthResponse {
@Field()
access_token: string;
@Field(() => User)
user: User;
}
@Resolver()
export class AuthResolver {
constructor(private authService: AuthService) {}
@Mutation(() => AuthResponse)
async login(
@Args('username') username: string,
@Args('password') password: string,
) {
return this.authService.login(username, password);
}
@Mutation(() => AuthResponse)
async register(
@Args('username') username: string,
@Args('email') email: string,
@Args('password') password: string,
) {
return this.authService.register(username, email, password);
}
}