android flesh out
This commit is contained in:
@@ -8,7 +8,18 @@ import {
|
||||
RemoveMemberSchema,
|
||||
UpdateRoleSchema,
|
||||
} from "../schemas/user";
|
||||
import { getUserById, updateUser, deleteUser, createUserWithPassword, authenticateUser } from "~/server/services/user.service";
|
||||
import {
|
||||
getUserById,
|
||||
updateUser,
|
||||
deleteUser,
|
||||
createUserWithPassword,
|
||||
authenticateUser,
|
||||
authenticateWithGoogle,
|
||||
refreshAccessToken,
|
||||
forgotPassword,
|
||||
resetPassword,
|
||||
revokeUserSessions,
|
||||
} from "~/server/services/user.service";
|
||||
import {
|
||||
getFamilyGroup,
|
||||
inviteMember,
|
||||
@@ -27,6 +38,23 @@ const SignupSchema = object({
|
||||
password: string([minLength(8)]),
|
||||
});
|
||||
|
||||
const GoogleAuthSchema = object({
|
||||
idToken: string([minLength(1)]),
|
||||
});
|
||||
|
||||
const RefreshTokenSchema = object({
|
||||
refreshToken: string([minLength(1)]),
|
||||
});
|
||||
|
||||
const ForgotPasswordSchema = object({
|
||||
email: string([emailVal()]),
|
||||
});
|
||||
|
||||
const ResetPasswordSchema = object({
|
||||
token: string([minLength(1)]),
|
||||
password: string([minLength(8)]),
|
||||
});
|
||||
|
||||
export const userRouter = createTRPCRouter({
|
||||
login: publicProcedure
|
||||
.input(wrap(LoginSchema))
|
||||
@@ -37,10 +65,31 @@ export const userRouter = createTRPCRouter({
|
||||
signup: publicProcedure
|
||||
.input(wrap(SignupSchema))
|
||||
.mutation(async ({ input }) => {
|
||||
const user = await createUserWithPassword(input.name, input.email, input.password);
|
||||
const { createSession } = await import("~/server/auth/session");
|
||||
const session = await createSession(user.id);
|
||||
return { user, sessionToken: session.sessionToken };
|
||||
return createUserWithPassword(input.name, input.email, input.password);
|
||||
}),
|
||||
|
||||
googleAuth: publicProcedure
|
||||
.input(wrap(GoogleAuthSchema))
|
||||
.mutation(async ({ input }) => {
|
||||
return authenticateWithGoogle(input.idToken);
|
||||
}),
|
||||
|
||||
refreshToken: publicProcedure
|
||||
.input(wrap(RefreshTokenSchema))
|
||||
.mutation(async ({ input }) => {
|
||||
return refreshAccessToken(input.refreshToken);
|
||||
}),
|
||||
|
||||
forgotPassword: publicProcedure
|
||||
.input(wrap(ForgotPasswordSchema))
|
||||
.mutation(async ({ input }) => {
|
||||
return forgotPassword(input.email);
|
||||
}),
|
||||
|
||||
resetPassword: publicProcedure
|
||||
.input(wrap(ResetPasswordSchema))
|
||||
.mutation(async ({ input }) => {
|
||||
return resetPassword(input.token, input.password);
|
||||
}),
|
||||
|
||||
me: protectedProcedure.query(async ({ ctx }) => {
|
||||
@@ -60,6 +109,11 @@ export const userRouter = createTRPCRouter({
|
||||
return { success: true };
|
||||
}),
|
||||
|
||||
logout: protectedProcedure.mutation(async ({ ctx }) => {
|
||||
await revokeUserSessions(ctx.user.id);
|
||||
return { success: true };
|
||||
}),
|
||||
|
||||
listFamilyMembers: protectedProcedure.query(async ({ ctx }) => {
|
||||
const group = await getFamilyGroup(ctx.user.id);
|
||||
return group.members;
|
||||
|
||||
Reference in New Issue
Block a user