Rayy
Rayy
CCConvex Community
Created by Rayy on 6/3/2024 in #support-community
Getting adapter error with Next Auth and Convex in production.
Oh God, it was such a dumb error. I forgot to add my env variables in the production. 🙂
4 replies
CCConvex Community
Created by Rayy on 6/3/2024 in #support-community
Getting adapter error with Next Auth and Convex in production.
This is the error I am getting,
lib/adapter:getUserByAccount
failure
31ms
Uncaught Error: Adapter API called without correct secret value
at checkSecret (../../convex/lib/adapter.ts:34:2)
at input (../../convex/lib/adapter.ts:19:4)
at handler (../../node_modules/convex-helpers/dist/server/customFunctions.js:87:36)
lib/adapter:getUserByAccount
failure
31ms
Uncaught Error: Adapter API called without correct secret value
at checkSecret (../../convex/lib/adapter.ts:34:2)
at input (../../convex/lib/adapter.ts:19:4)
at handler (../../node_modules/convex-helpers/dist/server/customFunctions.js:87:36)
This is probably the function returning the error,
function checkSecret(secret: string) {
if (secret !== process.env.CONVEX_AUTH_ADAPTER_SECRET) {
throw new Error("Adapter API called without correct secret value");
}
}
function checkSecret(secret: string) {
if (secret !== process.env.CONVEX_AUTH_ADAPTER_SECRET) {
throw new Error("Adapter API called without correct secret value");
}
}
But I have checked and I am passing in my environment variables a secret key as CONVEX_AUTH_ADAPTER_SECRET
4 replies
CCConvex Community
Created by Rayy on 5/21/2024 in #support-community
Unable to authenticate Convex with next auth when provider is Credentials.
How should I implement that to my existing code? Can you help me with it.
19 replies
CCConvex Community
Created by Rayy on 5/21/2024 in #support-community
Unable to authenticate Convex with next auth when provider is Credentials.
Hey @Michal Srb , This is the thread I came across https://github.com/nextauthjs/next-auth/issues/3970 So apparently the credentials provider does not fire the session callback.
19 replies
CCConvex Community
Created by Rayy on 5/21/2024 in #support-community
Unable to authenticate Convex with next auth when provider is Credentials.
Will be doing that. Thanks for the time tho.
19 replies
CCConvex Community
Created by Rayy on 5/21/2024 in #support-community
Unable to authenticate Convex with next auth when provider is Credentials.
This is what I get after adding debug as true
[auth][debug]: adapter_getSessionAndUser {
"args": [
"eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwia2lkIjoiSDlkdS1xaE16RXBaUjBhSUhIYVpXUnN0bnBZcnVwY2V2SFN5RHhOc3pfeEgtV0RnNHJPZ2o4M1UzSTRlWU5fYjVHLXdNVHVOOU1zNWtLZFprRGJuV2cifQ..fAWh7EV-iq1MMjSEhPYGzg.qN_eqRC-aycxiHqX1DZ8fY-PAPuV6bXyu7UEKBVDzk1g6sv6OF_SZon6OWZN5pEM5IhKdQByTrx4LmUrWnfv50XHdY1QShL6yvVKjb8s5irWFaPQ_8AMz5kKJqqslIbnm-yn3VyCbBuCxnNsgO0C4Bb85Jv_KcYSGDOdD7w6TVc8I24DStk8bnDgx5_TAc7rZGygH6VF-tEpNNkb5-QapQ.6CK7XCb-jAXCkBCk5SVUFgAZrnZkB_y80xmg4BaZg-Q"
]
}
[auth][debug]: adapter_getSessionAndUser {
"args": [
"eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwia2lkIjoiSDlkdS1xaE16RXBaUjBhSUhIYVpXUnN0bnBZcnVwY2V2SFN5RHhOc3pfeEgtV0RnNHJPZ2o4M1UzSTRlWU5fYjVHLXdNVHVOOU1zNWtLZFprRGJuV2cifQ..fAWh7EV-iq1MMjSEhPYGzg.qN_eqRC-aycxiHqX1DZ8fY-PAPuV6bXyu7UEKBVDzk1g6sv6OF_SZon6OWZN5pEM5IhKdQByTrx4LmUrWnfv50XHdY1QShL6yvVKjb8s5irWFaPQ_8AMz5kKJqqslIbnm-yn3VyCbBuCxnNsgO0C4Bb85Jv_KcYSGDOdD7w6TVc8I24DStk8bnDgx5_TAc7rZGygH6VF-tEpNNkb5-QapQ.6CK7XCb-jAXCkBCk5SVUFgAZrnZkB_y80xmg4BaZg-Q"
]
}
19 replies
CCConvex Community
Created by Rayy on 5/21/2024 in #support-community
Unable to authenticate Convex with next auth when provider is Credentials.
But it works when I set the session strategy as jwt, and in the jwt callback return the token. I feel like there is something I am misunderstanding here.
19 replies
CCConvex Community
Created by Rayy on 5/21/2024 in #support-community
Unable to authenticate Convex with next auth when provider is Credentials.
The signIn callback, logs the user and account
USER {
_creationTime: 1716284082776.5615,
_id: 'j572z018e0g9t800511wpmwzgh6sh56z',
email: '...',
emailVerified: 1716284125046,
password: '$2a$10$/vA1Y1bDolexsMk0KJErR.o0tDDfOWKZjsnQIDU49vq6YT8CGpLy2',
id: '53fea5c8-1574-4394-a812-ff86f944526e'
}
ACCOUNT {
providerAccountId: '53fea5c8-1574-4394-a812-ff86f944526e',
type: 'credentials',
provider: 'credentials'
}
USER {
_creationTime: 1716284082776.5615,
_id: 'j572z018e0g9t800511wpmwzgh6sh56z',
email: '...',
emailVerified: 1716284125046,
password: '$2a$10$/vA1Y1bDolexsMk0KJErR.o0tDDfOWKZjsnQIDU49vq6YT8CGpLy2',
id: '53fea5c8-1574-4394-a812-ff86f944526e'
}
ACCOUNT {
providerAccountId: '53fea5c8-1574-4394-a812-ff86f944526e',
type: 'credentials',
provider: 'credentials'
}
But the sessions callback logs null.
19 replies
CCConvex Community
Created by Rayy on 5/21/2024 in #support-community
Unable to authenticate Convex with next auth when provider is Credentials.
It does, i guess. getUserByEmail is actually a wrapper of the query being fetched.
export const getUserByEmail = (email: string) => {
return fetchQuery(api.users.getUserByEmail, {
email,
});
};
export const getUserByEmail = (email: string) => {
return fetchQuery(api.users.getUserByEmail, {
email,
});
};
I have a register form which calls the register action on submit.
export const register = async (values: RegisterSchema) => {
const validatedFields = registerSchema.safeParse(values);

if (!validatedFields.success) {
return { error: "Invdalid fields" };
}

const { email, password } = validatedFields.data;
const hashedPassword = await bcrypt.hash(password, 10);

try {
const existingUser = await getUserByEmail(email);

if (existingUser && existingUser.emailVerified) {
return { error: "You already have an account with us, please login." };
}

if (existingUser && !existingUser.emailVerified) {
await deleteUnverifiedUser(existingUser._id);
}

await createUser(email, hashedPassword);

const verificationCode = await generateTwoFactorCode(email);

const res = await sendVerificationEmail(
verificationCode.email,
verificationCode.code
);

if (res.error) {
return { error: "Something went wrong!" };
}

return { success: "A code has been sent to your email" };
} catch (error) {
throw error;
}
};
export const register = async (values: RegisterSchema) => {
const validatedFields = registerSchema.safeParse(values);

if (!validatedFields.success) {
return { error: "Invdalid fields" };
}

const { email, password } = validatedFields.data;
const hashedPassword = await bcrypt.hash(password, 10);

try {
const existingUser = await getUserByEmail(email);

if (existingUser && existingUser.emailVerified) {
return { error: "You already have an account with us, please login." };
}

if (existingUser && !existingUser.emailVerified) {
await deleteUnverifiedUser(existingUser._id);
}

await createUser(email, hashedPassword);

const verificationCode = await generateTwoFactorCode(email);

const res = await sendVerificationEmail(
verificationCode.email,
verificationCode.code
);

if (res.error) {
return { error: "Something went wrong!" };
}

return { success: "A code has been sent to your email" };
} catch (error) {
throw error;
}
};
Each function is actually a wrapper of the query or mutation being called from convex. My applicaiton registers the user just like it should, and I can see the data in the convex database, and I am able to login with the same too without any issues. I just am not able to authenticate it with Convex, so that I can authenticate my Convex functions.
19 replies
CCConvex Community
Created by Rayy on 5/21/2024 in #support-community
Unable to authenticate Convex with next auth when provider is Credentials.
Here you go.
19 replies
CCConvex Community
Created by Rayy on 5/21/2024 in #support-community
Unable to authenticate Convex with next auth when provider is Credentials.
export default {
providers: [
Google({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
Github({
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
}),
Credentials({
async authorize(credentials) {
const validatedFields = loginSchema.safeParse(credentials);

if (validatedFields.success) {
const { email, password } = validatedFields.data;

const user = await getUserByEmail(email);

if (!user || !user.password) return null;

const passwordsMatch = await bcrypt.compare(password, user.password);

if (passwordsMatch) return user;
}
return null;
},
}),
],
} satisfies NextAuthConfig;
export default {
providers: [
Google({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
Github({
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
}),
Credentials({
async authorize(credentials) {
const validatedFields = loginSchema.safeParse(credentials);

if (validatedFields.success) {
const { email, password } = validatedFields.data;

const user = await getUserByEmail(email);

if (!user || !user.password) return null;

const passwordsMatch = await bcrypt.compare(password, user.password);

if (passwordsMatch) return user;
}
return null;
},
}),
],
} satisfies NextAuthConfig;
19 replies
CCConvex Community
Created by Rayy on 5/20/2024 in #support-community
How to access mutations/queries from authAdapters in next auth convex setup?
Solved it @Michal Srb , thanks again.
6 replies
CCConvex Community
Created by Rayy on 5/20/2024 in #support-community
How to access mutations/queries from authAdapters in next auth convex setup?
It was that easy, lol. Thank you.
Cannot invoke an object which is possibly 'undefined'.ts(2722)
'ConvexAdapter.createUser' is possibly 'undefined'.ts(18048)
Cannot invoke an object which is possibly 'undefined'.ts(2722)
'ConvexAdapter.createUser' is possibly 'undefined'.ts(18048)
I am getting this typescript error tho?
6 replies
CCConvex Community
Created by Rayy on 5/20/2024 in #support-community
How to access mutations/queries from authAdapters in next auth convex setup?
@Michal Srb, Next.js server
6 replies
CCConvex Community
Created by Rayy on 5/19/2024 in #support-community
What is the difference between preloading query vs fetching queries in server components?
Ah, that explains it. Thank you.
3 replies
CCConvex Community
Created by Rayy on 1/29/2024 in #support-community
Is there a way around to call actions from non functional components?
That’s so amazing. 🔥
9 replies
CCConvex Community
Created by Rayy on 3/2/2024 in #support-community
How to get results from paginate Queries?
Ahh got it, just had to scroll all the way to the bottom to check how to use cursor. Thanks tho.
3 replies
CCConvex Community
Created by Hosna Qasmei on 3/2/2024 in #support-community
Is it possible to call a mutation in a Next.js API route?
Have you tried fetchMutation? You can check the docs in here, https://docs.convex.dev/client/react/nextjs/server-rendering
3 replies
CCConvex Community
Created by Rayy on 2/28/2024 in #support-community
How to handle errors in scheduled functions and display that error to the frontend?
This will work just fine, I guess. Will try it. Thanks guys. 🙂
13 replies
CCConvex Community
Created by Rayy on 2/28/2024 in #support-community
How to handle errors in scheduled functions and display that error to the frontend?
About that, I'd need to get the id of the scheduled function and then query the status of the scheduled function to get the error message, right?
13 replies