refactor: update remaining error imports to use ErrorCode

- Replace Err.Code with ErrorCode throughout convex model files
- Update error() function calls to use new signature
- Remove unused Err namespace imports

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2025-11-08 18:03:10 +00:00
parent f20f1a93c7
commit 94d6a22ab2
8 changed files with 136 additions and 144 deletions

View File

@@ -1,5 +1,5 @@
import type { Id } from "@fileone/convex/dataModel" import type { Id } from "@fileone/convex/dataModel"
import { v } from "convex/values" import { ConvexError, v } from "convex/values"
import { import {
authenticatedMutation, authenticatedMutation,
authenticatedQuery, authenticatedQuery,
@@ -8,19 +8,19 @@ import {
import * as Directories from "./model/directories" import * as Directories from "./model/directories"
import * as Files from "./model/files" import * as Files from "./model/files"
import * as User from "./model/user" import * as User from "./model/user"
import * as Err from "./shared/error" import { ErrorCode, error } from "./shared/error"
export const generateUploadUrl = authenticatedMutation({ export const generateUploadUrl = authenticatedMutation({
handler: async (ctx) => { handler: async (ctx) => {
const usageStatistics = await User.queryCachedUsageStatistics(ctx) const userInfo = await User.queryInfo(ctx)
if (!usageStatistics) { if (!userInfo) {
throw Err.create(Err.Code.Internal, "Internal server error") throw new ConvexError({ message: "Internal server error" })
} }
if ( if (userInfo.storageUsageBytes >= userInfo.storageQuotaBytes) {
usageStatistics.storageUsageBytes >= throw new ConvexError({
usageStatistics.storageQuotaBytes code: ErrorCode.StorageQuotaExceeded,
) { message: "Storage quota exceeded",
throw Err.create(Err.Code.Forbidden, "Storage quota exceeded") })
} }
return await ctx.storage.generateUploadUrl() return await ctx.storage.generateUploadUrl()
}, },
@@ -53,7 +53,10 @@ export const fetchDirectory = authenticatedQuery({
handler: async (ctx, { directoryId }) => { handler: async (ctx, { directoryId }) => {
const directory = await authorizedGet(ctx, directoryId) const directory = await authorizedGet(ctx, directoryId)
if (!directory) { if (!directory) {
throw new Error("Directory not found") error({
code: ErrorCode.NotFound,
message: "Directory not found",
})
} }
return await Directories.fetch(ctx, { directoryId }) return await Directories.fetch(ctx, { directoryId })
}, },
@@ -67,7 +70,10 @@ export const createDirectory = authenticatedMutation({
handler: async (ctx, { name, directoryId }): Promise<Id<"directories">> => { handler: async (ctx, { name, directoryId }): Promise<Id<"directories">> => {
const parentDirectory = await authorizedGet(ctx, directoryId) const parentDirectory = await authorizedGet(ctx, directoryId)
if (!parentDirectory) { if (!parentDirectory) {
throw new Error("Parent directory not found") error({
code: ErrorCode.NotFound,
message: "Parent directory not found",
})
} }
return await Directories.create(ctx, { return await Directories.create(ctx, {
@@ -76,56 +82,3 @@ export const createDirectory = authenticatedMutation({
}) })
}, },
}) })
export const saveFile = authenticatedMutation({
args: {
name: v.string(),
directoryId: v.id("directories"),
storageId: v.id("_storage"),
},
handler: async (ctx, { name, storageId, directoryId }) => {
const directory = await authorizedGet(ctx, directoryId)
if (!directory) {
throw new Error("Directory not found")
}
const now = Date.now()
const fileMetadata = await Promise.all([
ctx.db.system.get(storageId),
ctx.user.queryUsageStatistics(),
])
if (!fileMetadata) {
throw Err.create(Err.Code.Internal, "Internal server error")
}
await Promise.all([
ctx.db.insert("files", {
name,
size: fileMetadata.size,
storageId,
directoryId,
userId: ctx.user._id,
mimeType,
createdAt: now,
updatedAt: now,
}),
])
},
})
export const renameFile = authenticatedMutation({
args: {
directoryId: v.optional(v.id("directories")),
itemId: v.id("files"),
newName: v.string(),
},
handler: async (ctx, { directoryId, itemId, newName }) => {
const file = await authorizedGet(ctx, itemId)
if (!file) {
throw new Error("File not found")
}
await Files.renameFile(ctx, { directoryId, itemId, newName })
},
})

View File

@@ -1,4 +1,4 @@
import { v } from "convex/values" import { ConvexError, v } from "convex/values"
import { import {
apiKeyAuthenticatedQuery, apiKeyAuthenticatedQuery,
authenticatedMutation, authenticatedMutation,
@@ -16,7 +16,7 @@ import {
VDirectoryHandle, VDirectoryHandle,
VFileSystemHandle, VFileSystemHandle,
} from "./model/filesystem" } from "./model/filesystem"
import * as Err from "./shared/error" import { createErrorData, ErrorCode, error } from "./shared/error"
import type { import type {
DirectoryHandle, DirectoryHandle,
FileHandle, FileHandle,
@@ -36,10 +36,10 @@ export const moveItems = authenticatedMutation({
targetDirectoryHandle.id, targetDirectoryHandle.id,
) )
if (!targetDirectory) { if (!targetDirectory) {
throw Err.create( error({
Err.Code.DirectoryNotFound, code: ErrorCode.NotFound,
`Directory ${targetDirectoryHandle.id} not found`, message: `Directory ${targetDirectoryHandle.id} not found`,
) })
} }
const directoryHandles: DirectoryHandle[] = [] const directoryHandles: DirectoryHandle[] = []
@@ -81,10 +81,10 @@ export const moveToTrash = authenticatedMutation({
for (const handle of handles) { for (const handle of handles) {
const item = await authorizedGet(ctx, handle.id) const item = await authorizedGet(ctx, handle.id)
if (!item) { if (!item) {
throw Err.create( error({
Err.Code.NotFound, code: ErrorCode.NotFound,
`Item ${handle.id} not found`, message: `Item ${handle.id} not found`,
) })
} }
} }
@@ -105,7 +105,7 @@ export const moveToTrash = authenticatedMutation({
}) })
const results = await Promise.allSettled(promises) const results = await Promise.allSettled(promises)
const errors: Err.ApplicationErrorData[] = [] const errors = []
const okHandles: FileSystemHandle[] = [] const okHandles: FileSystemHandle[] = []
for (const result of results) { for (const result of results) {
switch (result.status) { switch (result.status) {
@@ -113,7 +113,7 @@ export const moveToTrash = authenticatedMutation({
okHandles.push(result.value) okHandles.push(result.value)
break break
case "rejected": case "rejected":
errors.push(Err.createJson(Err.Code.Internal)) errors.push(createErrorData(ErrorCode.Internal))
break break
} }
} }

View File

@@ -14,7 +14,7 @@ import {
} from "convex-helpers/server/customFunctions" } from "convex-helpers/server/customFunctions"
import * as ApiKey from "./model/apikey" import * as ApiKey from "./model/apikey"
import { type AuthUser, userIdentityOrThrow, userOrThrow } from "./model/user" import { type AuthUser, userIdentityOrThrow, userOrThrow } from "./model/user"
import * as Err from "./shared/error" import { ErrorCode, error } from "./shared/error"
export type AuthenticatedQueryCtx = QueryCtx & { export type AuthenticatedQueryCtx = QueryCtx & {
user: AuthUser user: AuthUser
@@ -65,7 +65,10 @@ export const apiKeyAuthenticatedQuery = customQuery(query, {
}, },
input: async (ctx, args) => { input: async (ctx, args) => {
if (!(await ApiKey.verifyApiKey(ctx, args.apiKey))) { if (!(await ApiKey.verifyApiKey(ctx, args.apiKey))) {
throw Err.create(Err.Code.Unauthenticated, "Invalid API key") error({
code: ErrorCode.Unauthenticated,
message: "Invalid API key",
})
} }
return { ctx: ctx as ApiKeyAuthenticatedQueryCtx, args } return { ctx: ctx as ApiKeyAuthenticatedQueryCtx, args }
}, },
@@ -80,7 +83,10 @@ export const apiKeyAuthenticatedMutation = customMutation(mutation, {
}, },
input: async (ctx, args) => { input: async (ctx, args) => {
if (!(await ApiKey.verifyApiKey(ctx, args.apiKey))) { if (!(await ApiKey.verifyApiKey(ctx, args.apiKey))) {
throw Err.create(Err.Code.Unauthenticated, "Invalid API key") error({
code: ErrorCode.Unauthenticated,
message: "Invalid API key",
})
} }
return { ctx, args } return { ctx, args }
}, },

View File

@@ -4,7 +4,8 @@ import type {
AuthenticatedQueryCtx, AuthenticatedQueryCtx,
} from "../functions" } from "../functions"
import { authorizedGet } from "../functions" import { authorizedGet } from "../functions"
import * as Err from "../shared/error" import type { ApplicationErrorData } from "../shared/error"
import { createErrorData, ErrorCode, error } from "../shared/error"
import { import {
type DirectoryHandle, type DirectoryHandle,
type DirectoryPath, type DirectoryPath,
@@ -30,10 +31,10 @@ export async function fetchHandle(
): Promise<Doc<"directories">> { ): Promise<Doc<"directories">> {
const directory = await authorizedGet(ctx, handle.id) const directory = await authorizedGet(ctx, handle.id)
if (!directory) { if (!directory) {
throw Err.create( error({
Err.Code.DirectoryNotFound, code: ErrorCode.NotFound,
`Directory ${handle.id} not found`, message: `Directory ${handle.id} not found`,
) })
} }
return directory return directory
} }
@@ -44,10 +45,10 @@ export async function fetch(
): Promise<DirectoryInfo> { ): Promise<DirectoryInfo> {
const directory = await authorizedGet(ctx, directoryId) const directory = await authorizedGet(ctx, directoryId)
if (!directory) { if (!directory) {
throw Err.create( error({
Err.Code.DirectoryNotFound, code: ErrorCode.NotFound,
`Directory ${directoryId} not found`, message: `Directory ${directoryId} not found`,
) })
} }
const path: DirectoryPath = [ const path: DirectoryPath = [
@@ -66,7 +67,10 @@ export async function fetch(
}) })
parentDirId = parentDir.parentId parentDirId = parentDir.parentId
} else { } else {
throw Err.create(Err.Code.DirectoryNotFound, "Parent directory not found") error({
code: ErrorCode.NotFound,
message: "Parent directory not found",
})
} }
} }
@@ -135,10 +139,10 @@ export async function create(
): Promise<Id<"directories">> { ): Promise<Id<"directories">> {
const parentDir = await authorizedGet(ctx, parentId) const parentDir = await authorizedGet(ctx, parentId)
if (!parentDir) { if (!parentDir) {
throw Err.create( error({
Err.Code.DirectoryNotFound, code: ErrorCode.NotFound,
`Parent directory ${parentId} not found`, message: `Parent directory ${parentId} not found`,
) })
} }
const existing = await ctx.db const existing = await ctx.db
@@ -153,10 +157,10 @@ export async function create(
.first() .first()
if (existing) { if (existing) {
throw Err.create( error({
Err.Code.DirectoryExists, code: ErrorCode.DirectoryExists,
`Directory with name ${name} already exists in ${parentId ? `directory ${parentId}` : "root"}`, message: `Directory with name ${name} already exists in ${parentId ? `directory ${parentId}` : "root"}`,
) })
} }
const now = Date.now() const now = Date.now()
@@ -183,10 +187,10 @@ export async function move(
sourceDirectories.map((directory) => sourceDirectories.map((directory) =>
authorizedGet(ctx, directory.id).then((d) => { authorizedGet(ctx, directory.id).then((d) => {
if (!d) { if (!d) {
throw Err.create( error({
Err.Code.DirectoryNotFound, code: ErrorCode.NotFound,
`Directory ${directory.id} not found`, message: `Directory ${directory.id} not found`,
) })
} }
return ctx.db return ctx.db
.query("directories") .query("directories")
@@ -202,14 +206,14 @@ export async function move(
), ),
) )
const errors: Err.ApplicationErrorData[] = [] const errors: ApplicationErrorData[] = []
const okDirectories: DirectoryHandle[] = [] const okDirectories: DirectoryHandle[] = []
conflictCheckResults.forEach((result, i) => { conflictCheckResults.forEach((result, i) => {
if (result.status === "fulfilled") { if (result.status === "fulfilled") {
if (result.value) { if (result.value) {
errors.push( errors.push(
Err.createJson( createErrorData(
Err.Code.Conflict, ErrorCode.Conflict,
`Directory ${targetDirectory.id} already contains a directory with name ${result.value.name}`, `Directory ${targetDirectory.id} already contains a directory with name ${result.value.name}`,
), ),
) )
@@ -217,7 +221,7 @@ export async function move(
okDirectories.push(sourceDirectories[i]!) okDirectories.push(sourceDirectories[i]!)
} }
} else if (result.status === "rejected") { } else if (result.status === "rejected") {
errors.push(Err.createJson(Err.Code.Internal)) errors.push(createErrorData(ErrorCode.Internal))
} }
}) })
@@ -243,7 +247,7 @@ export async function move(
for (const updateResult of results) { for (const updateResult of results) {
if (updateResult.status === "rejected") { if (updateResult.status === "rejected") {
errors.push(Err.createJson(Err.Code.Internal)) errors.push(createErrorData(ErrorCode.Internal))
} }
} }
@@ -335,11 +339,11 @@ export async function deletePermanently(
const deleteResults = await Promise.allSettled(deleteDirectoryPromises) const deleteResults = await Promise.allSettled(deleteDirectoryPromises)
const errors: Err.ApplicationErrorData[] = [] const errors: ApplicationErrorData[] = []
let successfulDeletions = 0 let successfulDeletions = 0
for (const result of deleteResults) { for (const result of deleteResults) {
if (result.status === "rejected") { if (result.status === "rejected") {
errors.push(Err.createJson(Err.Code.Internal)) errors.push(createErrorData(ErrorCode.Internal))
} else { } else {
successfulDeletions += 1 successfulDeletions += 1
} }
@@ -378,11 +382,11 @@ export async function restore(
const restoreResults = await Promise.allSettled(restoreDirectoryPromises) const restoreResults = await Promise.allSettled(restoreDirectoryPromises)
const errors: Err.ApplicationErrorData[] = [] const errors: ApplicationErrorData[] = []
let successfulRestorations = 0 let successfulRestorations = 0
for (const result of restoreResults) { for (const result of restoreResults) {
if (result.status === "rejected") { if (result.status === "rejected") {
errors.push(Err.createJson(Err.Code.Internal)) errors.push(createErrorData(ErrorCode.Internal))
} else { } else {
successfulRestorations += 1 successfulRestorations += 1
} }

View File

@@ -1,6 +1,7 @@
import type { Doc, Id } from "@fileone/convex/dataModel" import type { Doc, Id } from "@fileone/convex/dataModel"
import { type AuthenticatedMutationCtx, authorizedGet } from "../functions" import { type AuthenticatedMutationCtx, authorizedGet } from "../functions"
import * as Err from "../shared/error" import type { ApplicationErrorData } from "../shared/error"
import { createErrorData, ErrorCode, error } from "../shared/error"
import type { DirectoryHandle, FileHandle } from "../shared/filesystem" import type { DirectoryHandle, FileHandle } from "../shared/filesystem"
export async function renameFile( export async function renameFile(
@@ -27,10 +28,10 @@ export async function renameFile(
.first() .first()
if (existing) { if (existing) {
throw Err.create( error({
Err.Code.FileExists, code: ErrorCode.FileExists,
`File with name ${newName} already exists in ${directoryId ? `directory ${directoryId}` : "root"}`, message: `File with name ${newName} already exists in ${directoryId ? `directory ${directoryId}` : "root"}`,
) })
} }
await ctx.db.patch(itemId, { name: newName, updatedAt: Date.now() }) await ctx.db.patch(itemId, { name: newName, updatedAt: Date.now() })
@@ -50,10 +51,10 @@ export async function move(
items.map((fileHandle) => items.map((fileHandle) =>
authorizedGet(ctx, fileHandle.id).then((f) => { authorizedGet(ctx, fileHandle.id).then((f) => {
if (!f) { if (!f) {
throw Err.create( error({
Err.Code.FileNotFound, code: ErrorCode.NotFound,
`File ${fileHandle.id} not found`, message: `File ${fileHandle.id} not found`,
) })
} }
return ctx.db return ctx.db
.query("files") .query("files")
@@ -69,14 +70,14 @@ export async function move(
), ),
) )
const errors: Err.ApplicationErrorData[] = [] const errors: ApplicationErrorData[] = []
const okFiles: FileHandle[] = [] const okFiles: FileHandle[] = []
conflictCheckResults.forEach((result, i) => { conflictCheckResults.forEach((result, i) => {
if (result.status === "fulfilled") { if (result.status === "fulfilled") {
if (result.value) { if (result.value) {
errors.push( errors.push(
Err.createJson( createErrorData(
Err.Code.Conflict, ErrorCode.Conflict,
`Directory ${targetDirectoryHandle.id} already contains a file with name ${result.value.name}`, `Directory ${targetDirectoryHandle.id} already contains a file with name ${result.value.name}`,
), ),
) )
@@ -84,7 +85,7 @@ export async function move(
okFiles.push(items[i]) okFiles.push(items[i])
} }
} else if (result.status === "rejected") { } else if (result.status === "rejected") {
errors.push(Err.createJson(Err.Code.Internal)) errors.push(createErrorData(ErrorCode.Internal))
} }
}) })
@@ -99,7 +100,7 @@ export async function move(
for (const updateResult of results) { for (const updateResult of results) {
if (updateResult.status === "rejected") { if (updateResult.status === "rejected") {
errors.push(Err.createJson(Err.Code.Internal)) errors.push(createErrorData(ErrorCode.Internal))
} }
} }
@@ -136,11 +137,11 @@ export async function deletePermanently(
const deleteResults = await Promise.allSettled(deleteFilePromises) const deleteResults = await Promise.allSettled(deleteFilePromises)
const errors: Err.ApplicationErrorData[] = [] const errors: ApplicationErrorData[] = []
let successfulDeletions = 0 let successfulDeletions = 0
for (const result of deleteResults) { for (const result of deleteResults) {
if (result.status === "rejected") { if (result.status === "rejected") {
errors.push(Err.createJson(Err.Code.Internal)) errors.push(createErrorData(ErrorCode.Internal))
} else { } else {
successfulDeletions += 1 successfulDeletions += 1
} }
@@ -179,11 +180,11 @@ export async function restore(
const restoreResults = await Promise.allSettled(restoreFilePromises) const restoreResults = await Promise.allSettled(restoreFilePromises)
const errors: Err.ApplicationErrorData[] = [] const errors: ApplicationErrorData[] = []
let successfulRestorations = 0 let successfulRestorations = 0
for (const result of restoreResults) { for (const result of restoreResults) {
if (result.status === "rejected") { if (result.status === "rejected") {
errors.push(Err.createJson(Err.Code.Internal)) errors.push(createErrorData(ErrorCode.Internal))
} else { } else {
successfulRestorations += 1 successfulRestorations += 1
} }

View File

@@ -1,3 +1,4 @@
import { ConvexError } from "convex/values"
import type { Doc, Id } from "../_generated/dataModel" import type { Doc, Id } from "../_generated/dataModel"
import type { MutationCtx } from "../_generated/server" import type { MutationCtx } from "../_generated/server"
import type { import type {
@@ -5,7 +6,7 @@ import type {
AuthenticatedMutationCtx, AuthenticatedMutationCtx,
AuthenticatedQueryCtx, AuthenticatedQueryCtx,
} from "../functions" } from "../functions"
import * as Err from "../shared/error" import { ErrorCode, error } from "../shared/error"
export async function create( export async function create(
ctx: MutationCtx, ctx: MutationCtx,
@@ -22,7 +23,7 @@ export async function create(
}) })
const doc = await ctx.db.get(id) const doc = await ctx.db.get(id)
if (!doc) { if (!doc) {
throw Err.create(Err.Code.Internal, "Failed to create file share") throw new ConvexError({ message: "Failed to create file share" })
} }
return doc return doc
} }
@@ -46,11 +47,17 @@ export async function find(
.withIndex("byShareToken", (q) => q.eq("shareToken", shareToken)) .withIndex("byShareToken", (q) => q.eq("shareToken", shareToken))
.first() .first()
if (!doc) { if (!doc) {
throw Err.create(Err.Code.NotFound, "File share not found") error({
code: ErrorCode.NotFound,
message: "File share not found",
})
} }
if (hasExpired(doc)) { if (hasExpired(doc)) {
throw Err.create(Err.Code.NotFound, "File share not found") error({
code: ErrorCode.NotFound,
message: "File share not found",
})
} }
return doc return doc

View File

@@ -1,11 +1,11 @@
import { v } from "convex/values" import { ConvexError, v } from "convex/values"
import type { Doc, Id } from "../_generated/dataModel" import type { Doc, Id } from "../_generated/dataModel"
import { import {
type AuthenticatedMutationCtx, type AuthenticatedMutationCtx,
type AuthenticatedQueryCtx, type AuthenticatedQueryCtx,
authorizedGet, authorizedGet,
} from "../functions" } from "../functions"
import * as Err from "../shared/error" import { ErrorCode, error } from "../shared/error"
import type { import type {
DirectoryHandle, DirectoryHandle,
FileHandle, FileHandle,
@@ -174,7 +174,10 @@ export async function deleteItemsPermanently(
export async function emptyTrash(ctx: AuthenticatedMutationCtx) { export async function emptyTrash(ctx: AuthenticatedMutationCtx) {
const rootDir = await queryRootDirectory(ctx) const rootDir = await queryRootDirectory(ctx)
if (!rootDir) { if (!rootDir) {
throw Err.create(Err.Code.NotFound, "user root directory not found") error({
code: ErrorCode.NotFound,
message: "user root directory not found",
})
} }
const dirs = await ctx.db const dirs = await ctx.db
@@ -221,12 +224,18 @@ export async function fetchFileUrl(
): Promise<string> { ): Promise<string> {
const file = await authorizedGet(ctx, fileId) const file = await authorizedGet(ctx, fileId)
if (!file) { if (!file) {
throw Err.create(Err.Code.NotFound, "file not found") error({
code: ErrorCode.NotFound,
message: "file not found",
})
} }
const url = await ctx.storage.getUrl(file.storageId) const url = await ctx.storage.getUrl(file.storageId)
if (!url) { if (!url) {
throw Err.create(Err.Code.NotFound, "file not found") error({
code: ErrorCode.NotFound,
message: "file not found",
})
} }
return url return url
@@ -238,7 +247,10 @@ export async function openFile(
) { ) {
const file = await authorizedGet(ctx, fileId) const file = await authorizedGet(ctx, fileId)
if (!file) { if (!file) {
throw Err.create(Err.Code.NotFound, "file not found") error({
code: ErrorCode.NotFound,
message: "file not found",
})
} }
const fileShare = await FilePreview.find(ctx, { const fileShare = await FilePreview.find(ctx, {
@@ -281,7 +293,10 @@ export async function saveFile(
) { ) {
const directory = await authorizedGet(ctx, directoryId) const directory = await authorizedGet(ctx, directoryId)
if (!directory) { if (!directory) {
throw Err.create(Err.Code.NotFound, "directory not found") error({
code: ErrorCode.NotFound,
message: "directory not found",
})
} }
const [fileMetadata, userInfo] = await Promise.all([ const [fileMetadata, userInfo] = await Promise.all([
@@ -289,7 +304,7 @@ export async function saveFile(
User.queryInfo(ctx), User.queryInfo(ctx),
]) ])
if (!fileMetadata || !userInfo) { if (!fileMetadata || !userInfo) {
throw Err.create(Err.Code.Internal, "Internal server error") throw new ConvexError({ message: "Internal server error" })
} }
if ( if (
@@ -297,7 +312,10 @@ export async function saveFile(
userInfo.storageQuotaBytes userInfo.storageQuotaBytes
) { ) {
await ctx.storage.delete(storageId) await ctx.storage.delete(storageId)
throw Err.create(Err.Code.StorageQuotaExceeded, "Storage quota exceeded") error({
code: ErrorCode.StorageQuotaExceeded,
message: "Storage quota exceeded",
})
} }
const now = Date.now() const now = Date.now()

View File

@@ -2,7 +2,7 @@ import type { MutationCtx, QueryCtx } from "@fileone/convex/server"
import type { Doc } from "../_generated/dataModel" import type { Doc } from "../_generated/dataModel"
import { authComponent } from "../auth" import { authComponent } from "../auth"
import { type AuthenticatedQueryCtx, authorizedGet } from "../functions" import { type AuthenticatedQueryCtx, authorizedGet } from "../functions"
import * as Err from "../shared/error" import { ErrorCode, error } from "../shared/error"
export type AuthUser = Awaited<ReturnType<typeof authComponent.getAuthUser>> export type AuthUser = Awaited<ReturnType<typeof authComponent.getAuthUser>>
@@ -12,7 +12,10 @@ export type AuthUser = Awaited<ReturnType<typeof authComponent.getAuthUser>>
export async function userIdentityOrThrow(ctx: QueryCtx | MutationCtx) { export async function userIdentityOrThrow(ctx: QueryCtx | MutationCtx) {
const identity = await ctx.auth.getUserIdentity() const identity = await ctx.auth.getUserIdentity()
if (!identity) { if (!identity) {
throw Err.create(Err.Code.Unauthenticated, "Not authenticated") error({
code: ErrorCode.Unauthenticated,
message: "Not authenticated",
})
} }
return identity return identity
} }