Skip to content

Commit

Permalink
✨ Added api key to webapp updates
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Dec 25, 2023
1 parent 99ce3f1 commit e089a44
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions apps/webapp/src/hooks/mutations/useApiKeyMutation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const useApiKeyMutation = () => {
// Fetch the token
const loginResponse = await fetch(`${config.API_URL}/auth/login`, {
method: 'POST',
body: JSON.stringify({ id_user: data.userId.trim(), password_hash: 'password_hashed_her' }),
body: JSON.stringify({ id_user: data.userId.trim(), password_hash: 'pwd_audrey123' }),
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -22,7 +22,7 @@ const useApiKeyMutation = () => {
if (!loginResponse.ok) {
throw new Error('Failed to login');
}
const {access_token} = await loginResponse.json();
const { access_token } = await loginResponse.json();
//console.log("token is "+ access_token)

const response = await fetch(`${config.API_URL}/auth/generate-apikey`, {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/scripts/seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ INSERT INTO organizations (id_organization, name, stripe_customer_id) VALUES
('55222419-795d-4183-8478-361626363e58', 'Acme Inc', 'cust_stripe_acme_56604f75-7bf8-4541-9ab4-5928aade4bb8' );

INSERT INTO users (id_user, email, password_hash, first_name, last_name, id_organization) VALUES
('0ce39030-2901-4c56-8db0-5e326182ec6b', '[email protected]', 'password_hashed_here', 'Audrey', 'Aubry',
('0ce39030-2901-4c56-8db0-5e326182ec6b', '[email protected]', 'pwd_audrey123', 'Audrey', 'Aubry',
(SELECT id_organization FROM organizations WHERE name = 'Acme Inc'));

DO $$
Expand Down
1 change: 0 additions & 1 deletion packages/api/src/@core/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export class AuthController {

@ApiOperation({ operationId: 'getApiKeys', summary: 'Retrieve API Keys' })
@ApiResponse({ status: 200 })
@UseGuards(ApiKeyAuthGuard)
@Get('api-keys')
async apiKeys() {
return this.authService.getApiKeys();
Expand Down
9 changes: 8 additions & 1 deletion packages/api/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Controller, Get } from '@nestjs/common';
import { Controller, Get, UseGuards } from '@nestjs/common';
import { AppService } from './app.service';
import { LoggerService } from '@@core/logger/logger.service';
import { ApiKeyAuthGuard } from '@@core/auth/guards/api-key.guard';

@Controller()
export class AppController {
Expand All @@ -15,4 +16,10 @@ export class AppController {
getHello(): string {
return this.appService.getHello();
}

@UseGuards(ApiKeyAuthGuard)
@Get('protected')
getHello2(): string {
return `Hello You Are On The Panora API PROTECTED endpoint!`;
}
}

0 comments on commit e089a44

Please sign in to comment.