最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to pass redirect_uri in next-auth? - Stack Overflow

programmeradmin0浏览0评论

I do authorization via next-auth

import NextAuth from 'next-auth';

export default NextAuth({
    providers: [
        {
            id: 'reddit',
            name: 'Reddit',
            clientId: process.env.CLIENT_ID,
            clientSecret: process.env.CLIENT_SECRET,
            scope: 'read submit identity',
            type: 'oauth',
            version: '2.0',
            params: { grant_type: 'authorization_code' },
            accessTokenUrl: ' ',
            authorizationUrl: ';duration=permanent',
            profileUrl: '',
            profile: profile => {
                return {
                    id: profile.id as string,
                    name: profile.name,
                    email: null,
                };
            },
        },
    ],
});

And I am getting error from reddit /you sent an invalid request

  • invalid redirect_uri parameter./

How am I supposed to pass this uri in next-auth?

NEXTAUTH_URL variable is also specified

This is how next-auth inserts it into Request URL

redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fapi%2Fauth%2Fcallback%2Freddit

but I just need

http://localhost:8080

I do authorization via next-auth

import NextAuth from 'next-auth';

export default NextAuth({
    providers: [
        {
            id: 'reddit',
            name: 'Reddit',
            clientId: process.env.CLIENT_ID,
            clientSecret: process.env.CLIENT_SECRET,
            scope: 'read submit identity',
            type: 'oauth',
            version: '2.0',
            params: { grant_type: 'authorization_code' },
            accessTokenUrl: ' https://www.reddit./api/v1/access_token',
            authorizationUrl: 'https://www.reddit./api/v1/authorize?response_type=code&duration=permanent',
            profileUrl: 'https://oauth.reddit./api/v1/me',
            profile: profile => {
                return {
                    id: profile.id as string,
                    name: profile.name,
                    email: null,
                };
            },
        },
    ],
});

And I am getting error from reddit /you sent an invalid request

  • invalid redirect_uri parameter./

How am I supposed to pass this uri in next-auth?

NEXTAUTH_URL variable is also specified

This is how next-auth inserts it into Request URL

redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fapi%2Fauth%2Fcallback%2Freddit

but I just need

http://localhost:8080
Share Improve this question edited Oct 23, 2021 at 16:26 Андрей Кочанов asked Oct 23, 2021 at 16:04 Андрей КочановАндрей Кочанов 931 gold badge1 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

I solved it) u just need to set redirect_uri in your reddit app as

http://localhost:8080/api/auth/callback/reddit
发布评论

评论列表(0)

  1. 暂无评论