ReviewOS

also looking at this

stacks/postline

feat: crosspost to LinkedIn and Instagram

#1
Merged chris wants to merge feat/crosspost-linkedin-instagram into main
31 files +2335 -87
app/Actions/Postline/InstagramCallbackAction.tsadded+30-0
Changes to app/Actions/Postline/InstagramCallbackAction.ts
@@ -0,0 +1,30 @@
1import type { RequestInstance } from '@stacksjs/types'
2import { Action } from '@stacksjs/actions'
3import { response } from '@stacksjs/router'
4import { instagram } from '../../Services/Social/InstagramService'
5
6export default new Action({
7 name: 'Postline Instagram Callback',
8 description: 'Handle the Facebook OAuth redirect and store the Instagram 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?instagram=error&message=${encodeURIComponent(description)}`)
19 }
20
21 try {
22 await instagram.handleCallback(code, state)
23 return response.redirect('/accounts?instagram=connected')
24 }
25 catch (error) {
26 const message = error instanceof Error ? error.message : String(error)
27 return response.redirect(`/accounts?instagram=error&message=${encodeURIComponent(message)}`)
28 }
29 },
30})