Documentation
Providers
Reddit

Reddit Provider

reddit-logo

If you need a detailed guide on how to setup a provider pleaser refer to the Getting Started and Making your first integration guides.

Resources

Setup

Callback URL

https://your-app.com/api/auth/integration/reddit

Environment variables

.env.local
AUTH_REDDIT_ID=your-client-id
AUTH_REDDIT_SECRET=your-client-secret

Add the provider to the auth.ts file.

auth.ts
import { NextIntegrate } from 'next-integrate';
 
export const { auth } = NextIntegrate({
  // The URL of the app, e.g. https://example.com, set in the .env file.
  // If you want to modify the redirect URL, to be prefixed with something else,
  // you can do it here like this:
  // base_url: process.env.BASE_URL! + "/some-prefix",
  // This will change the redirect URL to eg. https://example.com/some-prefix/api/auth/integration/google
  base_url: process.env.BASE_URL!,
  providers: [
    {
      provider: 'reddit',
      client_id: process.env.AUTH_REDDIT_ID!,
      client_secret: process.env.AUTH_REDDIT_SECRET!,
      integrations: [],
    },
  ],
});

Add an integration

auth.ts
import { NextIntegrate } from 'next-integrate';
 
export const { auth } = NextIntegrate({
  // The URL of the app, e.g. https://example.com, set in the .env file.
  // If you want to modify the redirect URL, to be prefixed with something else,
  // you can do it here like this:
  // base_url: process.env.BASE_URL! + "/some-prefix",
  // This will change the redirect URL to eg. https://example.com/some-prefix/api/auth/integration/google
  base_url: process.env.BASE_URL!,
  providers: [
    {
      provider: 'reddit',
      client_id: process.env.AUTH_REDDIT_ID!,
      client_secret: process.env.AUTH_REDDIT_SECRET!,
      integrations: [
        {
          name: 'some_custom_name',
          options: {
            scope: 'identity edit',
            duration: 'permanent',
          },
          callback: async (data) => {
            // This is where you can save the data to a database, or do something else with it.
          },
        },
      ],
    },
  ],
});

Usage

To use the your new integration, you can use the <Integrate /> component found in the Getting Started Guide.

import Integrate from '@/components/integrate';
 
export default function Home() {
  return (
    <main>
      <Integrate provider="reddit" name="some_custom_name">
        Get Reddit User Info
      </Integrate>
    </main>
  );
}

Options

You can pass various parameters on the options object to customize the integration. The parameters are specific to the Reddit provider, please refer to the documentation (opens in a new tab), to verify the information if needed.

parametertyperequireddescription
durationstringtrueIndicates whether or not your app needs a permanent token. All bearer tokens expire after 1 hour. If you indicate you need permanent access to a user's account, you will additionally receive a refresh_token when acquiring the bearer token. You may use the refresh_token to acquire a new bearer token after your current token expires. Choose temporary if you're completing a one-time request for the user (such as analyzing their recent comments); choose permanent if you will be performing ongoing tasks for the user, such as notifying them whenever they receive a private message. The implicit grant flow does not allow permanent tokens.
scopestringtrueA list of scope strings that determines what the user will be prompted to give access to. You must explicitly request access to areas of the api, such as private messaging or moderator actions. See our automatically generated API docs. Scope Values: identity, edit, flair, history, modconfig, modflair, modlog, modposts, modwiki, mysubreddits, privatemessages, read, report, save, submit, subscribe, vote, wikiedit, wikiread.