feat: Projects backend slice — auth, primitives, backend, UI (#3)
This commit is contained in:
@@ -36,7 +36,33 @@ const createAuth = (ctx: GenericCtx<DataModel>) =>
|
||||
|
||||
export { createAuth };
|
||||
|
||||
export interface AuthUserView {
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
readonly email: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the authenticated user to the canonical web view. The returned `id`
|
||||
* is the Convex `identity.tokenIdentifier`, the stable authenticated identity
|
||||
* used across organization/conversation/Signal ownership. Returns null when no
|
||||
* identity is present or the Better Auth user row cannot be resolved.
|
||||
*/
|
||||
export const getCurrentUser = query({
|
||||
args: {},
|
||||
handler: (ctx) => authComponent.safeGetAuthUser(ctx),
|
||||
handler: async (ctx): Promise<AuthUserView | null> => {
|
||||
const identity = await ctx.auth.getUserIdentity();
|
||||
if (!identity) {
|
||||
return null;
|
||||
}
|
||||
const authUser = await authComponent.safeGetAuthUser(ctx);
|
||||
if (!authUser) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
email: authUser.email,
|
||||
id: identity.tokenIdentifier,
|
||||
name: authUser.name,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user