forked from MergeFi/backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.service.ts
More file actions
24 lines (21 loc) · 749 Bytes
/
Copy pathauth.service.ts
File metadata and controls
24 lines (21 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { User } from '../common/entities';
import { UsersService, UpsertFromGithubInput } from '../users/users.service';
@Injectable()
export class AuthService {
constructor(
private readonly usersService: UsersService,
private readonly jwtService: JwtService,
) {}
async loginWithGithub(
profile: UpsertFromGithubInput,
): Promise<{ user: User; accessToken: string }> {
const user = await this.usersService.upsertFromGithub(profile);
const accessToken = this.signToken(user);
return { user, accessToken };
}
signToken(user: User): string {
return this.jwtService.sign({ sub: user.id, username: user.username });
}
}