Skip to content

Commit

Permalink
Add route for fethcing user's own data
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksTeresh committed Apr 22, 2024
1 parent a11de4d commit c041b0e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/client/hooks/useLoggedInUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const useLoggedInUser = () => {
const queryKey = 'user'

const query = async (): Promise<User> => {
const { data } = await apiClient.get('/users/')
const { data } = await apiClient.get('/user/')

return data
}
Expand Down
3 changes: 2 additions & 1 deletion src/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import errorHandler from '../middleware/error'
import accessLogger from '../middleware/access'
import thesisRouter from './thesis'
import loginRouter from './login'
import userRouter from './user'

const router = express()

Expand All @@ -28,7 +29,7 @@ router.get('/ping', (_, res) => res.send('pong'))
router.get('/error', () => {
throw new Error('Test error')
})

router.use('/user', userRouter)
router.use('/theses', thesisRouter)
router.use('/login', loginRouter)

Expand Down
15 changes: 15 additions & 0 deletions src/server/routes/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import express from 'express'

import { RequestWithUser } from '../types'

const userRouter = express.Router()

userRouter.get('/', async (req: RequestWithUser, res: any) => {
const { user } = req

if (!user) return res.send({})

return res.send(user)
})

export default userRouter
6 changes: 6 additions & 0 deletions src/server/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Request } from 'express'

export interface UserInfo {
uid: string
hyPersonSisuId: string
Expand All @@ -19,3 +21,7 @@ export interface User {
iamGroups: string[]
newUser?: boolean
}

export interface RequestWithUser extends Request {
user: User
}

0 comments on commit c041b0e

Please sign in to comment.