File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -8,17 +8,15 @@ import {
8
8
createNewRole ,
9
9
memberGroupRole ,
10
10
} from "../typeDefinitions/discordMessage.types" ;
11
+ import { verifyBot } from "../utils/verifyAuthToken" ;
11
12
12
13
export async function createGuildRoleHandler ( request : IRequest , env : env ) {
13
14
const authHeader = request . headers . get ( "Authorization" ) ;
14
15
if ( ! authHeader ) {
15
16
return new JSONResponse ( response . BAD_SIGNATURE ) ;
16
17
}
17
- const authToken = authHeader . split ( " " ) [ 1 ] ;
18
18
try {
19
- await jwt . verify ( authToken , env . RDS_SERVERLESS_PUBLIC_KEY , {
20
- algorithm : "RS256" ,
21
- } ) ;
19
+ await verifyBot ( authHeader , env ) ;
22
20
const body : createNewRole = await request . json ( ) ;
23
21
24
22
const res = await createGuildRole ( body , env ) ;
Original file line number Diff line number Diff line change
1
+ import { env } from "../typeDefinitions/default.types" ;
2
+ import jwt from "@tsndr/cloudflare-worker-jwt" ;
3
+
4
+ /**
5
+ *
6
+ * @param authHeader { string } : the auth header of request
7
+ * @param env { env }: the ctx (context) which contains the secrets put in as wrangler secrets.
8
+ */
9
+
10
+ export async function verifyBot ( authHeader : string , env : env ) {
11
+ const authToken = authHeader . split ( " " ) [ 1 ] ;
12
+ await jwt . verify ( authToken , env . RDS_SERVERLESS_PUBLIC_KEY , {
13
+ algorithm : "RS256" ,
14
+ } ) ;
15
+ }
You can’t perform that action at this time.
0 commit comments