reddit auth problem..?

Please provide the following:

  1. SDK Version: 43
  2. Platforms(Android/iOS/web/all): all
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

I have copied the code from the example on authorizing a reddit app here Authentication - Expo Documentation.

For reference, here is my code

import React from 'react';
import { Linking } from 'react-native';
import * as WebBrowser from 'expo-web-browser';
import { makeRedirectUri, useAuthRequest } from 'expo-auth-session';
import { Button } from 'react-native-paper';
import { useAppDispatch } from '../../common/hooks/redux';
import { setAuthCode } from '../../common/state/authSlice';

WebBrowser.maybeCompleteAuthSession();

// Endpoint
const discovery = {
    authorizationEndpoint: 'https://www.reddit.com/api/v1/authorize.compact',
    tokenEndpoint: 'https://www.reddit.com/api/v1/access_token',
};

const LoginScreen = () => {
    const dispatch = useAppDispatch();
    const [request, response, promptAsync] = useAuthRequest(
        {
            clientId: 'CLIENT_ID',
            scopes: ['identity'],
            redirectUri: makeRedirectUri({
                // For usage in bare and standalone
                native: 'your.app://redirect',
            }),
        },
        discovery
    );

    React.useEffect(() => {
        if (response?.type === 'success') {
            const { code } = response.params;
            dispatch(setAuthCode(code));
        }
    }, [response]);

    return (
        <Button
            disabled={!request}
            onPress={() => {
                promptAsync();
            }}
        >
            Login
        </Button>
    );
};

export default LoginScreen;

However, when this link opens after pressing the login button, it simply takes me to a page that says ‘You broke reddit.’ without any further errors that might help me debug. I am getting no errors in the console running expo start, so I’m not sure where to go from here. Was the more customization I needed to do to that example code? The snack version of it isn’t building so I can’t verify if it’s just happening on my devices/emulators.

Update, I realized I needed to add my actual client ID in place of CLIENT_ID. I did that and it now takes me to a login screen where I can successfully log in, however rather than sending back success and a token, it tells me bad request, does not redirect, and then returns an object with type: dismiss to the app.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.