mirror of
https://github.com/get-drexa/drive.git
synced 2025-12-01 05:51:39 +00:00
- Add export mappings in @fileone/convex package.json for cleaner imports - Map @fileone/convex/dataModel to _generated/dataModel.d.ts - Map @fileone/convex/api to _generated/api.js - Map @fileone/convex/server to _generated/server.js - Update all imports across packages/convex and apps/drive-web - Maintain backward compatibility with _generated/* exports Co-authored-by: Ona <no-reply@ona.com>
26 lines
799 B
TypeScript
26 lines
799 B
TypeScript
import type { MutationCtx, QueryCtx } from "@fileone/convex/server"
|
|
import { authComponent } from "../auth"
|
|
import * as Err from "../shared/error"
|
|
|
|
export type AuthUser = Awaited<ReturnType<typeof authComponent.getAuthUser>>
|
|
|
|
/**
|
|
* Get the current authenticated user identity
|
|
* Throws an error if the user is not authenticated */
|
|
export async function userIdentityOrThrow(ctx: QueryCtx | MutationCtx) {
|
|
const identity = await ctx.auth.getUserIdentity()
|
|
if (!identity) {
|
|
throw Err.create(Err.Code.Unauthenticated, "Not authenticated")
|
|
}
|
|
return identity
|
|
}
|
|
|
|
/**
|
|
* Get user document from JWT authentication
|
|
* Throws an error if the user is not authenticated
|
|
*/
|
|
export async function userOrThrow(ctx: QueryCtx | MutationCtx) {
|
|
const user = await authComponent.getAuthUser(ctx)
|
|
return user
|
|
}
|