forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.controller.ts
More file actions
65 lines (60 loc) · 1.61 KB
/
Copy pathauth.controller.ts
File metadata and controls
65 lines (60 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {
Controller,
Post,
Body,
HttpCode,
HttpStatus,
Get,
} from "@nestjs/common";
import { Throttle } from "@nestjs/throttler";
import { AuthService } from "./auth.service";
import { NonceRequestDto, VerifyRequestDto } from "./dtos/auth.dto";
import { Auth, CurrentUser } from "./guard/auth.guard";
import { User } from "../users/user.entity";
@Controller("auth")
export class AuthController {
constructor(private readonly authService: AuthService) {}
/**
* POST /auth/nonce
* Returns a unique nonce for the given Stellar public key.
*/
@Post("nonce")
@Throttle({ default: { limit: 5, ttl: 900 } }) // 5 requests per 15 minutes
@HttpCode(HttpStatus.OK)
async nonce(@Body() dto: NonceRequestDto) {
return this.authService.generateNonce(dto);
}
/**
* POST /auth/verify
* Verifies the signed nonce and issues a JWT.
*/
@Post("verify")
@Throttle({ default: { limit: 5, ttl: 900 } }) // 5 requests per 15 minutes
@HttpCode(HttpStatus.OK)
async verify(@Body() dto: VerifyRequestDto) {
return this.authService.verify(dto);
}
/**
* GET /auth/me — example protected route
*/
@Auth()
@Get("me")
getProfile(@CurrentUser() user: User) {
return {
id: user.id,
publicKey: user.publicKey,
createdAt: user.createdAt,
pushNotificationsEnabled: user.pushNotificationsEnabled,
};
}
/**
* POST /auth/logout
* Revokes the caller's active JWT session(s) by bumping tokenVersion.
*/
@Auth()
@Post("logout")
@HttpCode(HttpStatus.NO_CONTENT)
async logout(@CurrentUser() user: User) {
await this.authService.logout(user.id);
}
}