-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Users unable to login on production build #710
Comments
Hi there! Hmm I wonder if you have a slightly different schema on production database than in development database (assuming you have more than one database)? If you are able to login in with a tool you can use to view and compare schemas on each database that might highlight any discrepancies. If you only have one database and are connecting to it in both development and production modes I'd be surprised to see this, but do let me know if that's the case! |
Hi ian, Indeed i tested by connecting the production build to the same DB i am using in the dev environment and I was still facing this issue. As a workaround I created two new views account_accounts and user_users in the db. For some reason in the production build, next-auth is trying to query account_accounts and user_users instead of accounts and users when using custom models. |
Thanks for the response! Hmm that is odd and I don't know why that is happening. It seems like it would be helpful to have this open to look at and for us to try and work out what is going on. |
Im seeing the same issue: //Simplifying
Running yarn dev gets:
Running with build / start (OR deploying to Vercel) gets:
|
We have the exact same issue, in dev mode it works perfectly, but on production mode it duplicates the table and you get |
Looking very quickly to the code, why is https://github.com/nextauthjs/next-auth/blob/main/src/adapters/typeorm/index.js#L72 needed on non production envs only? I think it might be related to the issue 🤔 Edit I just tried removing the environment check locally and that worked perfectly if (process.env.NODE_ENV !== 'production') {
await updateConnectionEntities(connection, config.entities)
} |
Since synchronising the schema is dangerous and removing that WorkaroundIf you have a custom model, for example you add a import Adapters from 'next-auth/adapters';
// Extend the built-in models using class inheritance
export default class User extends Adapters.TypeORM.Models.User.model {
// You can extend the options in a model but you should not remove the base
// properties or change the order of the built-in options on the constructor
constructor(name, email, image, emailVerified) {
super(name, email, image, emailVerified);
}
}
export const UserSchema = {
name: 'User',
target: User,
columns: {
...Adapters.TypeORM.Models.User.schema.columns,
role: {
type: 'varchar',
nullable: true,
},
},
}; instead do it without extending the class export default class User {
constructor(name, email, image, emailVerified) {
if (name) {
this.name = name;
}
if (email) {
this.email = email;
}
if (image) {
this.image = image;
}
if (emailVerified) {
const currentDate = new Date();
this.emailVerified = currentDate;
}
}
}
export const UserSchema = {
name: 'User',
target: User,
columns: {
id: {
primary: true,
type: 'int',
generated: true,
},
name: {
type: 'varchar',
nullable: true,
},
email: {
type: 'varchar',
unique: true,
nullable: true,
},
emailVerified: {
type: 'timestamp',
nullable: true,
},
image: {
type: 'varchar',
nullable: true,
},
createdAt: {
type: 'timestamp',
createDate: true,
},
updatedAt: {
type: 'timestamp',
updateDate: true,
},
role: {
type: 'varchar',
nullable: true,
},
},
}; this "solves" the problem. |
I can confirm I have the same issue and @fedekau "solution" works |
got into this too; I think @fedekau's hot fix work for many cases! But in my case I have another couple of api calls using the TypeORM adaptor to perform CURD operations with custom models, and I'm inconsistently getting some weird could be related to this: maybe something to do with the constraint in a serverless setting and some of the stuff in typeORM weren't implemented with serverless in mind? Hmm or could also be due to some optimsiation done in Vercel for the functional calls I guess. just opened a discussion here: vercel/vercel#5299 Really hoping to get this fixed before we launch our app : 0 |
@archywillhe Another way around this for now if your having problems is to manually rename it:
|
@glenames ohh interesting! I will give it a try! thanks mate! also: dou you know where can i read more about using update: unforuntaely still getting |
Hi there! It looks like this issue hasn't had any activity for a while. It will be closed if no further activity occurs. If you think your issue is still relevant, feel free to comment on it to keep it open. (Read more at #912) Thanks! |
Hi there! It looks like this issue hasn't had any activity for a while. To keep things tidy, I am going to close this issue for now. If you think your issue is still relevant, just leave a comment and I will reopen it. (Read more at #912) Thanks! |
Can we reopen this? It just happened to me on my production site; I redeployed and the issue went away, but it's kind of worrying that this can happen. |
I can't extend the User model to make it available. It seems to work for others in this issue.
|
Im having the same problem as @jmaister above trying to create a migration via typeorm. All models etc are in typescript and I am invoking the following
I get the following error:
tsconfig file used
custom user model:
|
Fixed by moving to Passport.js |
@jmaister so looks like their might be some issues with the new typescript work. After changing it to the following i was able to generate an initial typeorm migration.
|
Some of the replies ere are really helpful, especially this one from @fedekau which I think is a good one that should be followed up:
The comments above from @deep-c and the issues @archywillhe has linked to are also helpful and interesting. As this discussion seems to have become quite broad (and is about more than one specific thing; with no single action that seems obvious arising from this) I'm going to mark this issue as closed now and suggest that anyone with issues related to migration raise them in the Discussions area that we have now. Please do also raise a feature request if you can identify ways we could make changes (in code and/or documentation) to help folks avoid doing whatever they are doing that is triggering problems with table names. Likewise if we think there is a race condition or behaviour that is explicitly incorrect please do raise a bug about that behaviour. A critical thing we need to be able to understand why these are happening is code to replicate any problems - in particular we need to understand how folks are building and compiling their apps to see where the problem is. To confirm, I do not see these issues myself with either TypeORM or Prisma adapters on production sites, including in cases with custom models. Specific challenges I think we have include that the guidance we have on how to use custom models is sparse, it may need to be reviewed and I suspect there are some issues specific to folks using TypeScript run into too. There are also issues with different version of TypeORM from time to time, so understand what versions of libraries people are suing is also helpful when it comes to replicating problems. We do have working schema creation tests for a range of databases with the default adapter (Postgres, MySQL, MSSQL, MongoDB...) and they test table/collection creation/column types/indexes/etc. IIRC they do not current include examples of custom models but those should be easy to extend. We may wish to do that and then go back and see if we can improve some of the examples/tutorials for the default adapter. Feel free to create feature request to extend those example and link back to this issue. |
I am having an issue with next auth in production whenever I clink in sign in it shows /api/auth/signin?=true and reloads the page never signs in |
Your question
First of all, i am really sorry but I am bit new to next/nextauth. I started by cloning the example project and went from there. I have one enabled provider (discord). My issue is that everything works fine when i am running the dev build but as soon as I am running the production build (next start using npm or yarn build then start), users cannot login. I am getting "QueryFailedError: relation "account__accounts" does not exist"
What are you trying to do
Here's a snippet from my simple config:
When I am running yarn dev, everything is working as expected.
When I am switching to yarn build & yarn start using the same .env from the same machine, i am getting the following exception:
Now i understand from https://next-auth.js.org/errors that GET_USER_BY_PROVIDER_ACCOUNT_ID_ERROR means a DB interaction error but what I am failing to understand is why I am getting this error if I am running the build using the same .env and using the same db instance. I am using a postgres instance if that helps. I appreciate any assistance.
Feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
The text was updated successfully, but these errors were encountered: