// app/api/social/[platform]/route.ts
import { InstagramProvider, setupSocialAuth } from "naystack/socials";
export const { GET } = setupSocialAuth({
providers: [InstagramProvider],
endpoint: "https://yourapp.com/api/social",
redirectURL: "/profile",
errorRedirectURL: "/signup",
onConnect: async ({ platform, profile, tokens, userId }) => {
if (!userId) return "You are not logged in";
await saveSocialAccount(userId, platform, profile, tokens);
},
});
One OAuth route for every platform a user can connect.
Mount the GET handler on a dynamic segment —
app/api/social/[platform]/route.ts— and/api/social/instagram,/api/social/youtube, … are the same handler. It serves both the connect entry point (?state, no code → 302 to the platform's authorize URL) and the callback (?code).A native client can add
&returnTo=yourapp://profileto the entry point: it rides along in the OAuthstateand replacesredirectURL(and, with?error=,errorRedirectURL) at the end, so an auth session gets its custom-scheme callback instead of relying on a universal link to reopen the app.