naystack - v1.9.9
    Preparing search index...

    Function setupSocialAuth

    • 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://profile to the entry point: it rides along in the OAuth state and replaces redirectURL (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.

      Parameters

      Returns {
          GET: (
              req: NextRequest,
              ctx: { params: Promise<{ platform: string }> },
          ) => Promise<NextResponse<unknown>>;
      }

      // 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);
      },
      });