Skip to content

Commit b07be36

Browse files
committed
🔐 API Access Keys & Original Resources Removed
1 parent 3fa1c5c commit b07be36

File tree

5 files changed

+39
-14
lines changed

5 files changed

+39
-14
lines changed

src/handlers/auth.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { APIGatewayProxyResult, APIGatewayEvent, Handler } from "aws-lambda";
1+
import {
2+
APIGatewayProxyResult,
3+
Handler,
4+
APIGatewayProxyEvent,
5+
} from "aws-lambda";
26
import { session } from "../services/auth/getSession.service";
37
import { handleSignin } from "../services/auth/signin.service";
48
import { handleSignout } from "../services/auth/signout.service";
59
import { handleSignup } from "../services/auth/signup.service";
610

7-
type ProxyHandler = Handler<APIGatewayEvent, APIGatewayProxyResult>;
11+
type ProxyHandler = Handler<APIGatewayProxyEvent, APIGatewayProxyResult>;
812

913
export const authRoutes: ProxyHandler = async (event, context) => {
1014
try {
@@ -15,7 +19,7 @@ export const authRoutes: ProxyHandler = async (event, context) => {
1519
} else if (event.path === "/auth/signout" && event.httpMethod === "GET") {
1620
return await handleSignout();
1721
} else if (event.path === "/auth/session" && event.httpMethod === "GET") {
18-
return await session();
22+
return await session(event);
1923
} else {
2024
return {
2125
statusCode: 403,
+10-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { APIGatewayProxyResult, APIGatewayEvent, Handler } from "aws-lambda";
22
import { connectSupabase as supabase } from "../../utils/supabase";
33

4-
export const session = async (): Promise<APIGatewayProxyResult> => {
5-
const { data, error } = await supabase().auth.getSession();
4+
export const session = async (
5+
event: APIGatewayEvent
6+
): Promise<APIGatewayProxyResult> => {
7+
const {
8+
data: { user },
9+
error,
10+
} = await supabase().auth.getUser("jwt-token-here");
611

712
if (error) {
813
throw {
@@ -11,12 +16,13 @@ export const session = async (): Promise<APIGatewayProxyResult> => {
1116
stack: error,
1217
};
1318
}
14-
19+
// Keep the response in main handler it's better.
20+
// For this commit I am keeping it here
1521
return {
1622
statusCode: 201,
1723
body: JSON.stringify({
1824
message: "Session Collection Successful",
19-
data: data,
25+
data: user,
2026
}),
2127
};
2228
};

src/types/event.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare module "aws-lambda/trigger/api-gateway-proxy" {
2+
interface APIGatewayProxyEventBase<TAuthorizerContext> {
3+
user: Object;
4+
5+
// Hack so TAuthorizerContext is used, cannot prefix with _
6+
// as it must match the interface exactly for interface merging
7+
___: TAuthorizerContext;
8+
}
9+
}

src/utils/supabase.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ export const connectSupabase = (): SupabaseClient<any, string, any> => {
1919
if (!supabase) {
2020
console.log("New SupabaseClient Created!!");
2121

22-
supabase = createClient(
23-
"https://mdeunrgwldikrpqvffht.supabase.co",
24-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1kZXVucmd3bGRpa3JwcXZmZmh0Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NzkyMjM3NDMsImV4cCI6MTk5NDc5OTc0M30.gItWH0cRS3QkyAZMMBJZDSsClAKmWNWz-xSMbLatpl8",
25-
options
26-
);
22+
supabase = createClient("project-url", "anon-public-key", options);
2723
}
2824
console.log("SupabaseClient returned!!");
2925
return supabase;

template.yml

+12-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Resources:
3030
# Policies:
3131
# # Give Lambda basic execution Permission to the function
3232
# - AWSLambdaBasicExecutionRole
33-
Role: arn:aws:iam::665123895031:role/lambda-role-recruitment-portal-v1
33+
Role: arn:aws:iam::XXXXXXXXXXXXX:role/lambda-role-recruitment-portal-v1 #Role with LambdaBasicExecutionRole Policy
3434
Events:
3535
HealthCheckAPI:
3636
Type: Api
@@ -49,7 +49,7 @@ Resources:
4949
# Policies:
5050
# # Give Lambda basic execution Permission to the function
5151
# - AWSLambdaBasicExecutionRole
52-
Role: arn:aws:iam::665123895031:role/lambda-role-recruitment-portal-v1
52+
Role: arn:aws:iam::XXXXXXXXXXXXXX:role/lambda-role-recruitment-portal-v1 #Role with LambdaBasicExecutionRole Policy
5353
Events:
5454
SignUpAPI:
5555
Type: Api
@@ -61,6 +61,16 @@ Resources:
6161
Properties:
6262
Path: /auth/signin
6363
Method: post
64+
GetSessionAPI:
65+
Type: Api
66+
Properties:
67+
Path: /auth/session
68+
Method: get
69+
SignoutAPI:
70+
Type: Api
71+
Properties:
72+
Path: /auth/signout
73+
Method: get
6474

6575
Outputs:
6676
RecruitmentPortalURL:

0 commit comments

Comments
 (0)