Reddit

Get your Reddit Credentials

To use Reddit sign in, you need a client ID and client secret. You can get them from the Reddit Developer Portal.

  1. Click "Create App" or "Create Another App"
  2. Select "web app" as the application type
  3. Set the redirect URL to http://localhost:3000/api/auth/callback/reddit for local development
  4. For production, set it to your application's domain (e.g. https://example.com/api/auth/callback/reddit)
  5. After creating the app, you'll get the client ID (under the app name) and client secret

If you change the base path of the auth routes, make sure to update the redirect URL accordingly.

Configure the provider

To configure the provider, you need to import the provider and pass it to the social_providers option of the auth instance.

config/auth.rb
require "better_auth"

auth = BetterAuth.auth(
secret: ENV.fetch("BETTER_AUTH_SECRET"),
base_url: ENV.fetch("BETTER_AUTH_URL", "http://localhost:3000"),
social_providers: {
reddit: BetterAuth::SocialProviders.reddit(
  client_id: ENV.fetch("REDDIT_CLIENT_ID"),
  client_secret: ENV.fetch("REDDIT_CLIENT_SECRET")
)
}
)

Sign In with Reddit

To sign in with Reddit, call auth.api.sign_in_social on your Ruby auth instance. The endpoint body takes the following properties:

  • provider: The provider to use. It should be set to reddit.
server.rb
response = auth.api.sign_in_social(
body: {
provider: "reddit",
callback_url: "/dashboard",
error_callback_url: "/login",
disable_redirect: true
}
)

redirect_url = response.fetch(:url)

Additional Configuration

Scopes

By default, Reddit provides basic user information. If you need additional permissions, you can specify scopes in your auth configuration:

config/auth.rb
require "better_auth"

auth = BetterAuth.auth(
  secret: ENV.fetch("BETTER_AUTH_SECRET"),
  base_url: ENV.fetch("BETTER_AUTH_URL", "http://localhost:3000"),
  social_providers: {
    reddit: BetterAuth::SocialProviders.reddit(
      client_id: ENV.fetch("REDDIT_CLIENT_ID"),
      client_secret: ENV.fetch("REDDIT_CLIENT_SECRET"),
      duration: "permanent"
    )
  }
)

Common Reddit scopes include:

  • identity: Access basic account information
  • read: Access posts and comments
  • submit: Submit posts and comments
  • subscribe: Manage subreddit subscriptions
  • history: Access voting history

For a complete list of available scopes, refer to the Reddit OAuth2 documentation.

On this page