추가
This commit is contained in:
32
backend/api/auth/current-user.get.ts
Normal file
32
backend/api/auth/current-user.get.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { queryOne } from '../../utils/db'
|
||||
|
||||
/**
|
||||
* 현재 로그인 사용자 정보
|
||||
* GET /api/auth/current-user
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const userId = getCookie(event, 'user_id')
|
||||
|
||||
if (!userId) {
|
||||
return { user: null }
|
||||
}
|
||||
|
||||
const employee = await queryOne<any>(`
|
||||
SELECT * FROM wr_employee_info
|
||||
WHERE employee_id = $1 AND is_active = true
|
||||
`, [parseInt(userId)])
|
||||
|
||||
if (!employee) {
|
||||
deleteCookie(event, 'user_id')
|
||||
return { user: null }
|
||||
}
|
||||
|
||||
return {
|
||||
user: {
|
||||
employeeId: employee.employee_id,
|
||||
employeeName: employee.employee_name,
|
||||
employeeEmail: employee.employee_email,
|
||||
employeePosition: employee.employee_position
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user