#ConvexAuth
80 messages · Page 1 of 1 (latest)
Hi @vague ocean. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
The auth.getUserId(ctx) function is used to retrieve the current user's ID in Convex. If this function returns null, it means that the user is not authenticated or the user's ID could not be retrieved from the context.
There could be several reasons why you're getting null:
-
The function is being called before the user is authenticated. Make sure that your function is wrapped in an
Authenticatedcomponent to ensure it doesn't run until the user is authenticated. source (https://discord.com/channels/1019350475847499849/1197975099039547512) -
The user's ID is not listed as a provider in your
auth.config.tsfile. source (https://discord.com/channels/1019350475847499849/1265416856832049306) -
If you're using server-side rendering with Next.js, note that server-side authentication is not supported yet. source (https://discord.com/channels/1019350475847499849/1265416856832049306)
If you're still having trouble, you might find the authentication debugging guide (https://docs.convex.dev/auth/debug) helpful.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus while is still not supported in server-side. Do you have any alternative way for temporary?
Let me check the knowledge base for you. One moment! :books:
Yes, there are a few workarounds you can consider for handling authentication with server-side rendering (SSR) in Convex:
-
Client-side Authentication: You can handle authentication on the client-side. This means that your server-side code will not have access to the user's session, but your client-side code will. This is the most straightforward approach and works well if your server-side code does not need to know the user's identity. source (https://discord.com/channels/1019350475847499849/1228500762217418832)
-
Use Cookies: You can store the session ID in a cookie instead of local storage. This allows the server to read the session ID during server-side rendering. However, this approach has some security implications and may not be suitable for all applications. source (https://discord.com/channels/1019350475847499849/1228500762217418832)
-
Hybrid Rendering: You can use a hybrid rendering approach where some parts of your application are rendered on the server and others on the client. This allows you to perform data fetching and authentication on the client-side while still benefiting from server-side rendering for parts of your application. source (https://discord.com/channels/1019350475847499849/1228500762217418832)
Remember, these are temporary solutions until Convex supports server-side authentication. Always consider the security implications of these approaches and choose the one that best fits your application's needs.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus is there another way to store currentUser when loggedin?
Let me check the knowledge base for you. One moment! :books:
Yes, there are a couple of ways to store the current user when they log in using Convex:
- Call a mutation from the client: You can call a mutation when the user logs in from a
useEffecthook. After the mutation succeeds, you can update the local state to reflect that the user has been stored. Here's an example of a helper hook that does the job:
import { useUser } from "@clerk/clerk-react";
import { useConvexAuth } from "convex/react";
import { useEffect, useState } from "react";
import { useMutation } from "convex/react";
import { api } from "../convex/_generated/api";
import { Id } from "../convex/_generated/dataModel";
export function useStoreUserEffect() {
const { isLoading, isAuthenticated } = useConvexAuth();
const { user } = useUser();
const [userId, setUserId] = useState<Id<"users"> | null>(null);
const storeUser = useMutation(api.users.store);
useEffect(() => {
if (!isAuthenticated) {
return;
}
async function createUser() {
const id = await storeUser();
setUserId(id);
}
createUser();
return () => setUserId(null);
}, [isAuthenticated, storeUser, user?.id]);
return {
isLoading: isLoading || (isAuthenticated && userId === null),
isAuthenticated: isAuthenticated && userId !== null,
};
}
source (https://docs.convex.dev/auth/database-auth#calling-the-store-user-mutation-from-react)
- Implement a webhook: You can set up a webhook and have your identity provider call it whenever user information changes. This allows you to store user information not contained in the JWT. source (https://docs.convex.dev/auth/database-auth#set-up-webhooks)
Remember to ensure that the user has already been stored before using the current user's document in a query. You can do this by explicitly checking for this condition before rendering the components that call the query, or before redirecting to the authenticated portion of your app. source (https://docs.convex.dev/auth/database-auth#waiting-for-current-user-to-be-stored)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus server-side authentication is not supported yet, I'm trying to save info of current user. is there a way to store info of current user when loggedin?
Let me check the knowledge base for you. One moment! :books:
Yes, there are a couple of ways to store the current user when they log in using Convex:
- Call a mutation from the client: You can call a mutation when the user logs in from a
useEffecthook. After the mutation succeeds, you can update the local state to reflect that the user has been stored. Here's an example of a helper hook that does the job:
import { useUser } from "@clerk/clerk-react";
import { useConvexAuth } from "convex/react";
import { useEffect, useState } from "react";
import { useMutation } from "convex/react";
import { api } from "../convex/_generated/api";
import { Id } from "../convex/_generated/dataModel";
export function useStoreUserEffect() {
const { isLoading, isAuthenticated } = useConvexAuth();
const { user } = useUser();
const [userId, setUserId] = useState<Id<"users"> | null>(null);
const storeUser = useMutation(api.users.store);
useEffect(() => {
if (!isAuthenticated) {
return;
}
async function createUser() {
const id = await storeUser();
setUserId(id);
}
createUser();
return () => setUserId(null);
}, [isAuthenticated, storeUser, user?.id]);
return {
isLoading: isLoading || (isAuthenticated && userId === null),
isAuthenticated: isAuthenticated && userId !== null,
};
}
source (https://docs.convex.dev/auth/database-auth#calling-the-store-user-mutation-from-react)
- Implement a webhook: You can set up a webhook and have your identity provider call it whenever user information changes. This allows you to store user information not contained in the JWT. source (https://docs.convex.dev/auth/database-auth#set-up-webhooks)
Remember to ensure that the user has already been stored before using the current user's document in a query. You can do this by explicitly checking for this condition before rendering the components that call the query, or before redirecting to the authenticated portion of your app. source (https://docs.convex.dev/auth/database-auth#waiting-for-current-user-to-be-stored)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus I'm not using clerk, I'm using ConvexAuth in nextjs serverside
Let me check the knowledge base for you. One moment! :books:
If you're using ConvexAuth in a Next.js server-side environment, you can still store user information when they log in. Here's how you can do it:
-
Create a users table in Convex: You can store your users in a users table in Convex and sync relevant data from your auth provider. When the user signs up or logs in, get the Convex user based on the auth info. If there's no user, that's when you create one. source (https://discord.com/channels/1019350475847499849/1219309150635294782)
-
Use the Convex user for authorization: Once you have a user from your Convex table, you can use that for any authorization across your app. For example, if you only want members of a given team to be able to view that team's projects, you can write a function that takes the current Convex user document and asserts team membership, and run that before executing a privileged query. source (https://discord.com/channels/1019350475847499849/1219309150635294782)
-
Use helpers to simplify the process: There are helpers to make this a bit simpler too - Convex helpers, for example, gives a library and patterns for auth. source (https://discord.com/channels/1019350475847499849/1219309150635294782)
Here's an example of how you can get the user's ID in your Convex functions:
import { Auth } from "convex/server";
import { Id } from "./_generated/dataModel";
export async function getUserId(ctx: { auth: Auth }) {
const identity = await ctx.auth.getUserIdentity();
if (identity === null) {
return null;
}
const [userId] = identity.subject.split(";");
return userId as Id<"users">;
}
source (https://stack.convex.dev/nextauth)
Remember, these are temporary solutions until Convex supports server-side authentication. Always consider the security implications of these approaches and choose the one that best fits your application's needs.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus I already have signup and login on my application, frontend uses React, redux and tailwind CSS for styling, backend uses NodeJs and express, jsonwebtoken. frontend and backend are separated. So I want to add Convex Auth (OAuth) database I am using mongodb,,
Is it possible to add Convex Auth (OAuth) on that kind of project,, please give example if Yes,, I am new on convex
Let me check the knowledge base for you. One moment! :books:
Yes, it is possible to add Convex Auth (OAuth) to your existing project. Convex Auth is a library for implementing authentication directly within your Convex backend. It allows you to authenticate users without needing an authentication service or even a hosting server. Your application can be a React web app served from a CDN or a React Native mobile app.
Here are the steps to add Convex Auth to your existing project:
- Install Convex: Run the following command to install Convex:
npm create convex@latest
source (https://docs.convex.dev/auth/convex-auth)
-
Choose React (Vite) and Convex Auth: When prompted, choose
React (Vite)andConvex Auth. -
Follow the Setup Guide: Follow the full setup guide to add Convex Auth to your existing project. The guide can be found here (https://labs.convex.dev/auth/setup).
-
Implement Authentication Methods: Convex Auth enables you to implement the following authentication methods:
- Magic Links & OTPs - send a link or code via email
- OAuth - sign in with Github / Google / Apple etc.
- Passwords - including password reset flow and optional email verification
source (https://docs.convex.dev/auth/convex-auth)
Please note that Convex Auth is currently in beta, and the team is working on supporting authentication for Next.js server-side. If you have feedback or feature requests, you can let them know on Discord. source (https://docs.convex.dev/auth/convex-auth)
As for MongoDB, Convex is a global state management system that runs in the cloud, so it doesn't directly interact with MongoDB. However, you can use Convex to manage your application's state and use MongoDB for your database needs separately.
Remember, integrating Convex Auth into an existing project might require some adjustments to your current setup. Always consider the implications of these changes and choose the approach that best fits your application's needs.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@narrow sundial kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus that means I am only going to set up convex on my frontend project and implement it on my frontend, then the response from Authentication, I can add them both on my mongoDB and convex.
Let me check the knowledge base for you. One moment! :books:
Yes, that's correct. You can set up Convex on your frontend project and implement Convex Auth for user authentication. When a user signs up or logs in, you can store the user's information in both your MongoDB database and Convex.
Here's a general idea of how you can do it:
-
Set up Convex on your frontend: Install Convex and choose
React (Vite)andConvex Authduring setup. source (https://docs.convex.dev/auth/convex-auth) -
Implement Convex Auth: Implement the desired authentication methods (Magic Links & OTPs, OAuth, or Passwords). source (https://docs.convex.dev/auth/convex-auth)
-
Store user information: When a user signs up or logs in, store the user's information in your MongoDB database and Convex. You can do this by calling a mutation in Convex and an API endpoint in your backend that updates your MongoDB database.
Remember, Convex is a state management system and doesn't directly interact with MongoDB. You'll need to handle the interaction between your application, Convex, and MongoDB. Always consider the implications of these changes and choose the approach that best fits your application's needs.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@narrow sundial kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus
how to resolve this error?
Error: {"code":"NoAuthProvider","message":"No auth provider found matching the given token"}
this is my fetch code
const user = await fetchQuery(
api.users.getuser,
{
id: "jx7c4p0zjrgn1byaqw3hve6szs6yeh4y" as Id<"users">,
},
{ token: convexAuthNextjsToken() },
);
Let me check the knowledge base for you. One moment! :books:
The error message {"code":"NoAuthProvider","message":"No auth provider found matching the given token"} indicates that the authentication provider specified in your Convex configuration does not match the token provided in the request.
Here are a few things you can check to resolve this issue:
-
Check your Convex configuration: Ensure that the authentication provider specified in your Convex configuration matches the token provided in the request. The auth config is specified in
convex/auth.config.jsin the code you deploy. If those use environment variables, likeprocess.env.CLERK_ISSUER_URLthen you set the environment variables in the appropriate prod/dev settings. source (https://discord.com/channels/1019350475847499849/1215800047606829086) -
Check your token: Make sure the token you're passing in the
fetchQueryfunction is valid and corresponds to the correct authentication provider. -
Check your server auth config: The error message suggests that there might be an issue with your server auth config. Make sure it's set up correctly. source (https://discord.com/channels/1019350475847499849/1212306162427371530)
If you're still having trouble, you might find the authentication debugging guide (https://docs.convex.dev/auth/debug) helpful. It provides a step-by-step guide to debug and resolve common authentication issues in Convex.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus I'm using ConvexAuth in NextJS (SSA)
Let me check the knowledge base for you. One moment! :books:
To make authenticated requests to Convex during server-side rendering in Next.js, you need to pass a JWT token to preloadQuery or fetchQuery in the third options argument. Here's an example:
import { preloadQuery } from "convex/nextjs";
import { api } from "@/convex/_generated/api";
import { Tasks } from "./Tasks";
export async function TasksWrapper() {
const token = await getAuthToken();
const preloadedTasks = await preloadQuery(
api.tasks.list,
{ list: "default" },
{ token },
);
return <Tasks preloadedTasks={preloadedTasks} />;
}
In this example, getAuthToken is a function that retrieves the JWT token. The implementation of getAuthToken depends on your authentication provider. Here are examples for Clerk and Auth0:
For Clerk:
import { auth } from "@clerk/nextjs";
export async function getAuthToken() {
return (await auth().getToken({ template: "convex" })) ?? undefined;
}
For Auth0:
import { getSession } from '@auth0/nextjs-auth0';
export async function getAuthToken() {
const { accessToken } = await getSession();
return accessToken;
}
source (https://docs.convex.dev/client/react/nextjs/server-rendering#server-side-authentication)
Please note that Convex is working on supporting authentication for Next.js server-side. If you have feedback or feature requests, you can let them know on Discord. source (https://discord.com/channels/1019350475847499849/1260676181498531861)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus
thiscode
const user = await fetchQuery(
api.users.getuser,
{
id: "jx7c4p0zjrgn1byaqw3hve6szs6yeh4y" as Id<"users">,
},
{ token: convexAuthNextjsToken() },
);
causing this error
Error: {"code":"NoAuthProvider","message":"No auth provider found matching the given token"}
with NextJS App router (SSA)
Let me check the knowledge base for you. One moment! :books:
The error message {"code":"NoAuthProvider","message":"No auth provider found matching the given token"} indicates that the authentication provider specified in your Convex configuration does not match the token provided in the request.
In your fetch code, you're using convexAuthNextjsToken() to get the token. This function should return a valid JWT token for the authenticated user. If it's not, you might want to check its implementation.
Here's how you can get the token in a Next.js server-side environment:
import { getSession } from '@auth0/nextjs-auth0';
export async function getAuthToken() {
const { accessToken } = await getSession();
return accessToken;
}
source (https://docs.convex.dev/client/react/nextjs/server-rendering#server-side-authentication)
Replace convexAuthNextjsToken() with getAuthToken() in your fetch code:
const user = await fetchQuery(
api.users.getuser,
{
id: "jx7c4p0zjrgn1byaqw3hve6szs6yeh4y" as Id<"users">,
},
{ token: await getAuthToken() },
);
Please note that Convex is working on supporting authentication for Next.js server-side. If you have feedback or feature requests, you can let them know on Discord. source (https://discord.com/channels/1019350475847499849/1260676181498531861)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus I'm not using Auth0 or clerk, the one I used is ConvexAuth
Let me check the knowledge base for you. One moment! :books:
If you're using ConvexAuth, you can use the convexAuthNextjsToken() function to get the token for the authenticated user. However, the error message you're seeing suggests that the token provided in the request does not match any auth provider in your Convex configuration.
Here are a few things you can check:
-
Check your Convex configuration: Ensure that ConvexAuth is correctly configured in your Convex setup. The auth config is specified in
convex/auth.config.jsin the code you deploy. If those use environment variables, likeprocess.env.CONVEX_AUTH_ISSUER_URLthen you set the environment variables in the appropriate prod/dev settings. -
Check your token: Make sure the token you're passing in the
fetchQueryfunction is valid and corresponds to ConvexAuth. You can do this by logging the token returned byconvexAuthNextjsToken()and verifying it. -
Check your server auth config: The error message suggests that there might be an issue with your server auth config. Make sure it's set up correctly.
If you're still having trouble, you might find the authentication debugging guide (https://docs.convex.dev/auth/debug) helpful. It provides a step-by-step guide to debug and resolve common authentication issues in Convex.
Please note that Convex is working on supporting authentication for Next.js server-side. If you have feedback or feature requests, you can let them know on Discord. source (https://discord.com/channels/1019350475847499849/1260676181498531861)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus is convex has a count function in db.query?
Let me check the knowledge base for you. One moment! :books:
Currently, Convex does not have a built-in count function for db.query. To get the count of items in a query, you would typically use the collect() function to get all items and then get the length of the returned array. Here's an example:
const items = await db.query("items").collect();
const count = items.length;
source (https://discord.com/channels/1019350475847499849/1258723651943923978)
However, this approach may not be performant for large datasets. For large datasets, it's recommended to store the count explicitly in a separate table and increment/decrement it as needed. This approach is known as denormalization. source (https://discord.com/channels/1019350475847499849/1179652755099500574)
Please note that Convex is designed to provide a few, simple ways to walk through and select documents from tables. There is no specific query language for complex logic like a join, an aggregation, or a group by. Instead, you can write the complex logic in JavaScript. source (https://docs.convex.dev/database/reading-data#more-complex-queries)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus how to use convexAuthNextjsToken() in convext/react-query?
Let me check the knowledge base for you. One moment! :books:
To use convexAuthNextjsToken() in convex/react-query, you need to pass the token to the useQuery or useMutation hooks as part of the options argument. Here's an example:
import { useQuery } from 'convex/react-query';
import { api } from '@/convex/_generated/api';
import { convexAuthNextjsToken } from 'your-token-provider';
const YourComponent = () => {
const { data, isLoading, error } = useQuery(
['getUser', { id: 'your-user-id' }],
() => api.users.get({ id: 'your-user-id' }, { token: convexAuthNextjsToken() }),
);
// Your component logic here
};
In this example, convexAuthNextjsToken() is a function that retrieves the JWT token for the authenticated user. You need to replace 'your-token-provider' and 'your-user-id' with the actual module and user ID.
Please note that the implementation of convexAuthNextjsToken() depends on your authentication setup. Make sure it's correctly implemented to return a valid JWT token.
Remember, Convex is working on supporting authentication for Next.js server-side. If you have feedback or feature requests, you can let them know on Discord. source (https://discord.com/channels/1019350475847499849/1260676181498531861)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus how can I achieve query per user input while typing using preloadQuery or fetchQuery?
Let me check the knowledge base for you. One moment! :books:
To achieve a query per user input while typing, you can use a combination of React's useState and useEffect hooks along with Convex's fetchQuery or preloadQuery. Here's a basic example:
import React, { useState, useEffect } from 'react';
import { fetchQuery } from 'convex/nextjs';
import { api } from '@/convex/_generated/api';
const SearchComponent = () => {
const [input, setInput] = useState('');
const [results, setResults] = useState(null);
useEffect(() => {
if (input) {
const fetchData = async () => {
const data = await fetchQuery(
api.yourApi.search,
{ query: input },
{ token: 'your-token' } // replace with your token retrieval method
);
setResults(data);
};
fetchData();
}
}, [input]);
return (
<div>
<input
type="text"
value={input}
onChange={(e) => setInput(e.target.value)}
/>
{/* Render your results here */}
</div>
);
};
In this example, api.yourApi.search should be replaced with the actual API endpoint you want to query, and 'your-token' should be replaced with the actual method of retrieving the token.
Please note that this will trigger a query every time the user types something, which might not be ideal for performance. To avoid this, you can implement a debounce function to delay the query until the user stops typing for a certain amount of time.
Remember, Convex is working on supporting authentication for Next.js server-side. If you have feedback or feature requests, you can let them know on Discord. source (https://discord.com/channels/1019350475847499849/1260676181498531861)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus how can I achive search by email or by name with one input field
Let me check the knowledge base for you. One moment! :books:
To achieve a search by email or by name with one input field, you can create a new field in your database that combines the email and name fields. Then, you can perform a search on this combined field. Here's an example of how you can do this in Convex:
- Create a new field that combines the email and name fields:
ctx.db.insert("users", {
email,
name,
searchField: `${email} ${name}`,
});
source (https://discord.com/channels/1019350475847499849/1192599574246850681)
- Update the new field whenever you're writing or updating the fields:
ctx.db.patch("users", id, {
email,
name,
searchField: `${email} ${name}`,
});
- Perform a search on the combined field:
const users = await ctx.db
.query("users")
.withSearchIndex("search_users", (q) =>
q.search("searchField", input)
)
.collect();
Please note that this approach requires you to manually keep the combined field up to date. Also, Convex doesn't support multi-field search out of the box, so this is essentially a workaround. source (https://discord.com/channels/1019350475847499849/1192599574246850681)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus is there a way to get table type?
Let me check the knowledge base for you. One moment! :books:
Yes, you can get the type of a table in Convex using TypeScript's mapped types and key lookup types. Here's how you can do it:
First, you can convert a table definition into the type of document in that table using a mapped type:
type DocFromTableDefinition<TableDef extends TableDefinition> = {
[Property in keyof TableDef]: TableDef[Property]["type"];
};
source (https://stack.convex.dev/end-to-end-ts#datamodelfromschemadefinition)
Then, you can use this to get the document type for each table in the schema definition:
type DataModelFromSchemaDefinition<SchemaDef extends SchemaDefinition> = {
[TableName in keyof SchemaDef]: DocFromTableDefinition<SchemaDef[TableName]>;
};
source (https://stack.convex.dev/end-to-end-ts#datamodelfromschemadefinition)
Finally, you can produce your data model from your schema definition:
type MyDataModel = DataModelFromSchemaDefinition<typeof schema>;
source (https://stack.convex.dev/end-to-end-ts#datamodelfromschemadefinition)
This will give you a type that represents the structure of your data in Convex. Please note that TypeScript might not simplify the result, giving you a complex type in your editor.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus in convexAuth with Google Provider, I want to change only name and lastname.
Let me check the knowledge base for you. One moment! :books:
To customize the name and last name of the user that gets authenticated with the Google provider in ConvexAuth, you can use the createOrUpdateUser callback function. This function is called when a user signs up or logs in, and you can use it to customize the user's information.
Here's an example of how you can do this:
import { convexAuth } from 'convex-nextjs';
import { Google } from 'convex-nextjs/auth-providers';
export const { auth, signIn, signOut, store } = convexAuth({
providers: [
Google({
id: 'google',
profile: (profile) => {
// Customize the profile here
return {
...profile,
name: 'New Name',
familyName: 'New Last Name',
};
},
}),
],
callbacks: {
async createOrUpdateUser(ctx, args) {
if (args.existingUserId) {
return args.existingUserId;
}
if (!args.profile.name) {
console.error('No name in profile', args.profile);
}
// Your logic here
},
},
});
In this example, the profile function is used to customize the user's profile. The createOrUpdateUser callback is then used to handle the customized profile.
Please note that the name field corresponds to the full name of the user, and the familyName field corresponds to the last name of the user. source (https://docs.convex.dev/api/interfaces/server.UserIdentity#name) source (https://docs.convex.dev/api/interfaces/server.UserIdentity#familyname)
Remember, Convex is working on supporting authentication for Next.js server-side. If you have feedback or feature requests, you can let them know on Discord. source (https://discord.com/channels/1019350475847499849/1260676181498531861)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus it seems I can't call my function
I created folder inside convex folder to separate query and mutation but I can't call it
Let me check the knowledge base for you. One moment! :books:
The issue you're experiencing might be due to the location of your test files. According to a support thread (https://discord.com/channels/1019350475847499849/1238203057271996597) on Discord, Convex currently requires all test files to be placed in the top-level convex/ folder. If you've nested your test file in a subfolder, it might not be able to find your functions.
Here's an example of how you can call functions in your test:
import { convexTest } from "convex-test";
import { test } from "vitest";
import { api, internal } from "./_generated/api";
test("functions", async () => {
const t = convexTest();
const x = await t.query(api.myFunctions.myQuery, { a: 1, b: 2 });
const y = await t.query(internal.myFunctions.internalQuery, { a: 1, b: 2 });
const z = await t.mutation(api.myFunctions.mutateSomething, { a: 1, b: 2 });
const w = await t.mutation(internal.myFunctions.mutateSomething, { a: 1 });
const u = await t.action(api.myFunctions.doSomething, { a: 1, b: 2 });
const v = await t.action(internal.myFunctions.internalAction, { a: 1, b: 2 });
});
source (https://docs.convex.dev/testing/convex-test#calling-functions-with-tquery-tmutation-and-taction)
If you're still having trouble, it might be due to your project setup. For example, one user reported issues when using vitest workspaces in a Next.js project. If you're using a similar setup, you might want to try removing the vitest.workspace.ts file to see if that resolves the issue. source (https://discord.com/channels/1019350475847499849/1238203057271996597)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@vague ocean kapa.ai is still learning and improving, please let us know how it did by reacting below
@spring citrus I can't find my functions in import { api } from "../convex/_generated/api";
Let me check the knowledge base for you. One moment! :books:
If you can't find your functions in import { api } from "../convex/_generated/api";, it might be due to one of the following reasons:
-
Your functions are not exported: Make sure your functions are exported from the file they are defined in. Convex functions should be exported as named exports.
-
Your functions are not in the
convexdirectory: Convex functions should be defined in theconvexdirectory at the root of your project. If they are in a different directory, they won't be included in the generatedapi. -
You haven't run code generation: Convex uses code generation to create the
apiobject. You need to runnpx convex devto generate theapiobject. If you've added new functions or made changes to existing ones, you need to run this command again to update theapi. -
Your functions are not correctly defined: Convex functions should be defined using the
query,mutation, oractionfunctions fromconvex/server. If they are not correctly defined, they won't be included in theapi.
Here's an example of how to define a Convex function:
import { query } from "convex/server";
export const myFunction = query(async ({ db }) => {
// Your function logic here
});
source (https://docs.convex.dev/functions/query-functions#defining-queries)