mirror of https://github.com/MaxLeiter/Drift
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			32 lines
		
	
	
		
			557 B
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			32 lines
		
	
	
		
			557 B
		
	
	
	
		
			TypeScript
		
	
import { Router } from "express"
 | 
						|
import jwt, { UserJwtRequest } from "@lib/middleware/jwt"
 | 
						|
import { User } from "@lib/models/User"
 | 
						|
 | 
						|
export const users = Router()
 | 
						|
 | 
						|
users.get("/self", jwt, async (req: UserJwtRequest, res, next) => {
 | 
						|
	const error = () =>
 | 
						|
		res.status(401).json({
 | 
						|
			message: "Unauthorized"
 | 
						|
		})
 | 
						|
 | 
						|
	try {
 | 
						|
		if (!req.user) {
 | 
						|
			return error()
 | 
						|
		}
 | 
						|
 | 
						|
		const user = await User.findByPk(req.user?.id, {
 | 
						|
			attributes: {
 | 
						|
				exclude: ["password"]
 | 
						|
			}
 | 
						|
		})
 | 
						|
		if (!user) {
 | 
						|
			return error()
 | 
						|
		}
 | 
						|
 | 
						|
		res.json(user)
 | 
						|
	} catch (error) {
 | 
						|
		next(error)
 | 
						|
	}
 | 
						|
})
 |