Show clicks only if user is authenticated

This commit is contained in:
2022-07-12 19:10:54 +02:00
parent 4813e05589
commit 80da55849b

View File

@@ -55,14 +55,24 @@ export default class LinksController {
}
}
public async index ({ response }: HttpContextContract) {
const links = await Link
.query()
.orderBy('id', 'asc')
.preload('author', (query) => {
query.select('email')
})
.preload('clicks')
public async index ({ response, auth }: HttpContextContract) {
let links: Link[]
if (auth.isAuthenticated && auth.isLoggedIn) {
links = await Link
.query()
.orderBy('id', 'asc')
.preload('author', (query) => {
query.select('email')
})
.preload('clicks')
} else {
links = await Link
.query()
.orderBy('id', 'asc')
.preload('author', (query) => {
query.select('email')
})
}
return response.status(200).send({
links
})