ahaan
ahaan12mo ago

```const identity = await ctx.auth.

const identity = await ctx.auth.getUserIdentity();
const identity = await ctx.auth.getUserIdentity();
isn't working for me. even when I am signed out, datas are being pushed to database, instead of throwing error
24 Replies
ahaan
ahaanOP12mo ago
a little more context:
export const createFile = mutation({
args: {
name: v.string(),
},
async handler(ctx, args) {
const identity = await ctx.auth.getUserIdentity();
if (identity === null) {
throw new Error("Unauthenticated call to mutation");
}

await ctx.db.insert("files", {
name: args.name,
});
},
});
export const createFile = mutation({
args: {
name: v.string(),
},
async handler(ctx, args) {
const identity = await ctx.auth.getUserIdentity();
if (identity === null) {
throw new Error("Unauthenticated call to mutation");
}

await ctx.db.insert("files", {
name: args.name,
});
},
});
@Web Dev Cody mate i follow the exact procedure as you do, but its not producing same result
Web Dev Cody
Web Dev Cody12mo ago
also, my code I probably do
if (!identity) {
throw new Error("Unauthenticated call to mutation");
}
if (!identity) {
throw new Error("Unauthenticated call to mutation");
}
I'm not sure if identity will return null or undefined if the user isn't logged in I don't recall writing identity === null
Web Dev Cody
Web Dev Cody12mo ago
GitHub
file-drive/convex/files.ts at main · webdevcody/file-drive
Contribute to webdevcody/file-drive development by creating an account on GitHub.
ahaan
ahaanOP12mo ago
oh right you didn't do the null part. Actually, first I went with what you wrote, then since it didn't work, I went to convex docs and tried going through stuff and found the null part, yet it doesn't work
ahaan
ahaanOP12mo ago
No description
Web Dev Cody
Web Dev Cody12mo ago
are you sure you are not logged in? like console log what identity is
ahaan
ahaanOP12mo ago
yeah I am not logged in, let me record a small clip
Web Dev Cody
Web Dev Cody12mo ago
you just need to add console.log(identity) and tell me what it prints out
ahaan
ahaanOP12mo ago
it doesn't print anything at all here is the entire code
import { ConvexError, v } from "convex/values";
import { mutation, query } from "./_generated/server";

export const createFile = mutation({
args: {
name: v.string(),
},
async handler(ctx, args) {
const identity = await ctx.auth.getUserIdentity();
console.log("Identity", identity);
if (!identity) {
throw new Error("Unauthenticated call to mutation");
}

await ctx.db.insert("files", {
name: args.name,
});
},
});

export const getFiles = query({
args: {},
async handler(ctx, args) {
return await ctx.db.query("files").collect();
},
});
import { ConvexError, v } from "convex/values";
import { mutation, query } from "./_generated/server";

export const createFile = mutation({
args: {
name: v.string(),
},
async handler(ctx, args) {
const identity = await ctx.auth.getUserIdentity();
console.log("Identity", identity);
if (!identity) {
throw new Error("Unauthenticated call to mutation");
}

await ctx.db.insert("files", {
name: args.name,
});
},
});

export const getFiles = query({
args: {},
async handler(ctx, args) {
return await ctx.db.query("files").collect();
},
});
ahaan
ahaanOP12mo ago
Web Dev Cody
Web Dev Cody12mo ago
check the logs in the convex dashboard or in your convex terminal also check if convex is failing to build due to a typescript error or something when I say "convex terminal", I mean go to vscode and click on your first terminal
ahaan
ahaanOP12mo ago
i just did that and no error pops up or no identity is being logged
Web Dev Cody
Web Dev Cody12mo ago
send me a screenshot of the terminal running npx convex dev
ahaan
ahaanOP12mo ago
okay I really feel embarrassed to say this, but I hadn't run the npx convex dev command. Now that I run it, its working totally fine. Sorry mate for troubling you and thank you very much for helping me I can't believe I forgot to run the command
Web Dev Cody
Web Dev Cody12mo ago
no worries, simply mistake glad you got it working!
unknown
unknown9mo ago
Please help me in the file drive app with nextjs @Web Dev Cody I was following your video end to end but It's not working as expecting it to be. When I try to upload a file I am getting this :
No description
unknown
unknown9mo ago
these are the env variable I am using
No description
unknown
unknown9mo ago
No description
unknown
unknown9mo ago
Please help me @Web Dev Cody to fix this one
unknown
unknown9mo ago
In this I am getting hasAccess value as null
No description
Web Dev Cody
Web Dev Cody9mo ago
@unknown double check the user you are logged in as has the orgs attached to their user info?
unknown
unknown9mo ago
I am getting this in my identity object
No description
unknown
unknown9mo ago
I am logging in with my own gmail account and also I have added a oragnization on clerk as well
unknown
unknown9mo ago
No description

Did you find this page helpful?