38c26f8b5c
* Add an API endpoint for fetching user info by username * Add endpoint for querying users by ID, too * Add very simple docs about user APIs
20 lines
651 B
TypeScript
20 lines
651 B
TypeScript
import { NextApiRequest, NextApiResponse } from 'next'
|
|
import { getUser } from 'web/lib/firebase/users'
|
|
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
|
|
import { LiteUser, ApiError, toLiteUser } from '../../_types'
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse<LiteUser | ApiError>
|
|
) {
|
|
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
|
|
const { id } = req.query
|
|
const user = await getUser(id as string)
|
|
if (!user) {
|
|
res.status(404).json({ error: 'User not found' })
|
|
return
|
|
}
|
|
res.setHeader('Cache-Control', 'no-cache')
|
|
return res.status(200).json(toLiteUser(user))
|
|
}
|