From 80da55849b3caaeab4d40b3856a805af1ebb34b8 Mon Sep 17 00:00:00 2001 From: Arthur DANJOU Date: Tue, 12 Jul 2022 19:10:54 +0200 Subject: [PATCH] Show clicks only if user is authenticated --- app/Controllers/Http/LinksController.ts | 26 +++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/app/Controllers/Http/LinksController.ts b/app/Controllers/Http/LinksController.ts index 520c8a0..1d312ea 100755 --- a/app/Controllers/Http/LinksController.ts +++ b/app/Controllers/Http/LinksController.ts @@ -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 })