also looking at this
feat: crosspost to LinkedIn and Instagram
#1
31 files
+2335
-87
| @@ -0,0 +1,30 @@ | ||
| 1 | import type { RequestInstance } from '@stacksjs/types' | |
| 2 | import { Action } from '@stacksjs/actions' | |
| 3 | import { response } from '@stacksjs/router' | |
| 4 | import { instagram } from '../../Services/Social/InstagramService' | |
| 5 | ||
| 6 | export 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 | }) | |