-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: addition of flow to create long lived access token using app id…
… and app secret
- Loading branch information
Showing
6 changed files
with
182 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "payload-instagram-plugin", | ||
"version": "0.0.10", | ||
"version": "0.1.0-beta.1", | ||
"type": "module", | ||
"homepage:": "https://github.com/tomashco/payload-instagram-plugin", | ||
"repository": "[email protected]:tomashco/payload-instagram-plugin.git", | ||
|
@@ -16,7 +16,7 @@ | |
"Instagram" | ||
], | ||
"scripts": { | ||
"dev": "cd dev && cross-env NODE_OPTIONS=--no-deprecation PAYLOAD_DROP_DATABASE='true' next dev --turbo", | ||
"dev": "cd dev && cross-env NODE_OPTIONS=--no-deprecation PAYLOAD_DROP_DATABASE='true' next dev --turbo --experimental-https", | ||
"build": "tsc", | ||
"test": "cd test && jest --config=./jest.config.js", | ||
"test:e2e": "cross-env NODE_OPTIONS=--no-deprecation NODE_NO_WARNINGS=1 tsx ./test/runE2E.ts", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { QueryClient, useMutation } from '@tanstack/react-query' | ||
import { addAppIdEndpoint } from '../../plugin' | ||
import { useRouter } from 'next/navigation' | ||
|
||
type useConfigInstagramType = { | ||
appId: string | ||
setAppId: React.Dispatch<React.SetStateAction<string>> | ||
setAppSecret: React.Dispatch<React.SetStateAction<string>> | ||
} | ||
|
||
const useConfigInstagram = ({ appId, setAppId, setAppSecret }: useConfigInstagramType) => { | ||
const router = useRouter() | ||
const { mutate: addAppId } = useMutation({ | ||
mutationFn: (body: { appId: string; appSecret: string }) => | ||
fetch(addAppIdEndpoint, { | ||
body: JSON.stringify({ | ||
...body, | ||
redirectUri: `${window.location.origin}/api/instagram/authorize`, | ||
}), | ||
method: 'POST', | ||
credentials: 'include', | ||
}).then(res => { | ||
if (!res.ok) throw new Error(res.status.toString()) | ||
return res.json() | ||
}), | ||
onSuccess: _res => { | ||
const redirectUri = `${window.location.origin}/api/instagram/authorize` | ||
const authorizeEndpoint = `https://api.instagram.com/oauth/authorize?client_id=${appId}&redirect_uri=${redirectUri}&scope=user_profile,user_media&response_type=code` | ||
router.push(authorizeEndpoint) | ||
setAppId('') | ||
setAppSecret('') | ||
}, | ||
onError: _res => { | ||
alert('Status: the configuration provided is not correct, try again') | ||
setAppId('') | ||
setAppSecret('') | ||
}, | ||
}) | ||
|
||
return { addAppId } | ||
} | ||
|
||
export default useConfigInstagram |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters