Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secure authentication page not working #5047

Closed
gleysonabreu opened this issue Jul 29, 2022 · 2 comments
Closed

Secure authentication page not working #5047

gleysonabreu opened this issue Jul 29, 2022 · 2 comments
Labels
prisma @auth/prisma-adapter question Ask how to do something or how something works

Comments

@gleysonabreu
Copy link

Question 馃挰

After adding the Prisma Adapter in the application for a test, the system started to suffer with redirects: "too many redirects in the browser".

How to reproduce 鈽曪笍

Code in index.tsx(login page):

export const getServerSideProps: GetServerSideProps = async (context: GetServerSidePropsContext) => {
  const session = await getSession(context);

  if (session) {
    return {
      redirect: {
        destination: '/account',
        permanent: false,
      }
    }
  }

  return {
    props: {}
  }
}

middleware:

import { withAuth } from "next-auth/middleware";

export default withAuth({
  pages: {
    signIn: '/',
    signOut: '/auth/signout',
    error: '/auth/error'
  },

});

export const config = { matcher: ["/account",] }

authOptions:

import NextAuth, { NextAuthOptions } from 'next-auth';
import TwitchProvider from 'next-auth/providers/twitch';
import GithubProvider from 'next-auth/providers/github';
import { PrismaAdapter } from '@next-auth/prisma-adapter';
import { prisma } from '../../../lib/prisma';

export const authOptions: NextAuthOptions = {
  providers: [
    TwitchProvider({
      clientId: process.env.NEXT_PUBLIC_TWITCH_ID as string,
      clientSecret: process.env.NEXT_PUBLIC_TWITCH_SECRET as string,
    }),
    GithubProvider({
      clientId: process.env.NEXT_PUBLIC_GITHUB_ID as string,
      clientSecret: process.env.NEXT_PUBLIC_GITHUB_SECRET as string
    }),
  ],
  adapter: PrismaAdapter(prisma),
}
export default NextAuth(authOptions);

So I found this issue and downloaded the experimental version and the redirects stopped but pages that unauthenticated users cannot access, they can access.

Matcher its not working??

Contributing 馃檶馃徑

No, I am afraid I cannot help regarding this

@gleysonabreu gleysonabreu added the question Ask how to do something or how something works label Jul 29, 2022
@github-actions github-actions bot added the prisma @auth/prisma-adapter label Jul 29, 2022
@balazsorban44
Copy link
Member

balazsorban44 commented Jul 30, 2022

Your middleware and NextAuth config should have the same custom pages config, otherwise NextAuth.js doesn't know where to redirect in your middleware. We are adding a better warning/detection for this in #5000

@gleysonabreu
Copy link
Author

Your middleware and NextAuth config should have the same custom pages config, otherwise NextAuth.js doesn't know where to redirect in your middleware. We are adding a better warning/detection for this in #5000

still not working here.
everything seems to work normally without the prisma adapter.
I downloaded the example given from the next-auth website and added the prisma adapter and it didn't work properly either.
Could you download the template and put the prisma adapter and see if the middleware works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prisma @auth/prisma-adapter question Ask how to do something or how something works
Projects
None yet
Development

No branches or pull requests

2 participants