@@ -96,19 +96,15 @@ app.get("/test", apiLimiter, (req: Request, res: Response) => {
9696// Slack Community Invite Endpoint (Protected)
9797app . get ( "/join-community" , apiLimiter , async ( req : Request , res : Response ) => {
9898 try {
99- // Get token from Authorization header or query parameter
100- let token : string | undefined ;
10199 const authHeader = req . headers . authorization ;
102100
103- if ( authHeader && authHeader . startsWith ( "Bearer " ) ) {
104- token = authHeader . substring ( 7 ) ; // Remove "Bearer " prefix
105- } else if ( req . query . token && typeof req . query . token === "string" ) {
106- token = req . query . token ;
101+ if ( ! authHeader || ! authHeader . startsWith ( "Bearer " ) ) {
102+ return res . status ( 401 ) . json ( {
103+ error : "Unauthorized - Authorization header with Bearer token required" ,
104+ } ) ;
107105 }
108106
109- if ( ! token ) {
110- return res . status ( 401 ) . json ( { error : "Unauthorized - Missing token" } ) ;
111- }
107+ const token = authHeader . substring ( 7 ) ;
112108
113109 // Verify token and get user
114110 let user ;
@@ -142,8 +138,10 @@ app.get("/join-community", apiLimiter, async (req: Request, res: Response) => {
142138 return res . status ( 500 ) . json ( { error : "Community invite not configured" } ) ;
143139 }
144140
145- // Redirect to Slack community
146- return res . redirect ( slackInviteUrl ) ;
141+ return res . status ( 200 ) . json ( {
142+ slackInviteUrl,
143+ message : "Subscription verified. You can join the community." ,
144+ } ) ;
147145 } catch ( error : any ) {
148146 console . error ( "Community invite error:" , error ) ;
149147 return res . status ( 500 ) . json ( { error : "Internal server error" } ) ;
0 commit comments