You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After switching out my database option with the adapter option, I can sign in and out with Google locally the same as before, but on my live site the same login fails and I get the message error=OAuthAccountNotLinked appended to URL.
Here is my [...nextauth].ts file:
import NextAuth from 'next-auth';
import Providers from 'next-auth/providers';
import Adapters from 'next-auth/adapters';
import Models from 'models';
const options = {
providers: [
Providers.Google({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
authorizationUrl:
'https://accounts.google.com/o/oauth2/auth?response_type=code',
}),
],
debug: true,
pages: {
signIn: '/signup',
signOut: '/',
error: '/signup/error', // Error code passed in query string as ?error=
verifyRequest: '/signup/verify-request', // (used for check email message)
},
adapter: Adapters.TypeORM.Adapter(
// The first argument should be a database connection string or TypeORM config object
{
type: 'postgres',
host: process.env.AWS_RDS_HOST,
port: process.env.AWS_RDS_PORT,
username: process.env.AWS_RDS_USERNAME,
password: process.env.AWS_RDS_PASSWORD,
database: process.env.AWS_RDS_DB,
},
// The second argument can be used to pass custom models and schemas
{
models: {
User: Models.User,
},
}
),
callbacks: {
session: async (session, user) => {
session.user.id = user.id;
session.user.username = user.username;
return Promise.resolve(session);
},
},
};
export default (req, res) => NextAuth(req, res, options);
And my models/User.ts file:
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,
// Adds a phoneNumber to the User schema
username: {
type: 'varchar',
nullable: true,
},
},
};
I manually created a username column in my postgres database, it's a varchar(60). My purpose for using the adapter is so that I can pass User a custom schema that includes username because after signing in with Google I still want the user to be able to a) create a unique username, and b) have that username passed into the session object.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
After switching out my
database
option with theadapter
option, I can sign in and out with Google locally the same as before, but on my live site the same login fails and I get the messageerror=OAuthAccountNotLinked
appended to URL.Here is my
[...nextauth].ts
file:And my
models/User.ts
file:I manually created a
username
column in my postgres database, it's avarchar(60)
. My purpose for using theadapter
is so that I can passUser
a custom schema that includesusername
because after signing in with Google I still want the user to be able to a) create a unique username, and b) have thatusername
passed into thesession
object.Any and all help is appreciated! Thanks everyone.
Beta Was this translation helpful? Give feedback.
All reactions