-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathauth.controller.ts
More file actions
36 lines (32 loc) · 1.06 KB
/
Copy pathauth.controller.ts
File metadata and controls
36 lines (32 loc) · 1.06 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
import { Request, Response, NextFunction } from 'express';
import { AuthService } from '../services/auth.service';
import { loginSchema } from '../utils/validation';
import { config } from '../config/env.config';
const authService = new AuthService();
export class AuthController {
async login(req: Request, res: Response, next: NextFunction) {
try {
if (config.env !== 'local' && config.env !== 'development' && config.env !== 'test') {
return res.status(403).json({
success: false,
error: 'Login endpoint is only available in local environment',
});
}
const validatedData = loginSchema.parse(req.body);
const result = await authService.login(validatedData);
return res.status(200).json({
success: true,
data: {
accessToken: result.session?.access_token,
refreshToken: result.session?.refresh_token,
user: {
id: result.user?.id,
email: result.user?.email,
},
},
});
} catch (error) {
next(error);
}
}
}