ReviewOS

also looking at this

stacks/postline

feat: crossposting — media (LinkedIn/IG/Threads), OAuth token refresh, and X/Twitter

#30
Merged glennmichael123 wants to merge feat/crosspost-media-and-token-refresh into main
28 files +1810 -109
app/Actions/Postline/TwitterCallbackAction.tsadded+30-0
Changes to app/Actions/Postline/TwitterCallbackAction.ts
@@ -0,0 +1,30 @@
1import type { RequestInstance } from '@stacksjs/types'
2import { Action } from '@stacksjs/actions'
3import { response } from '@stacksjs/router'
4import { twitter } from '../../Services/Social/TwitterService'
5
6export default new Action({
7 name: 'Postline Twitter Callback',
8 description: 'Handle the X/Twitter OAuth redirect and store the access token.',
9 method: 'GET',
10
11 async handle(request: RequestInstance) {
12 const code = String(request.get('code') || '')
13 const state = String(request.get('state') || '')
14 const oauthError = String(request.get('error') || '')
15
16 if (oauthError) {
17 const description = String(request.get('error_description') || oauthError)
18 return response.redirect(`/accounts?twitter=error&message=${encodeURIComponent(description)}`)
19 }
20
21 try {
22 await twitter.handleCallback(code, state)
23 return response.redirect('/accounts?twitter=connected')
24 }
25 catch (error) {
26 const message = error instanceof Error ? error.message : String(error)
27 return response.redirect(`/accounts?twitter=error&message=${encodeURIComponent(message)}`)
28 }
29 },
30})