Skip to content

Commit

Permalink
Merge branch 'main' into getting-started-server
Browse files Browse the repository at this point in the history
  • Loading branch information
dotmanki committed Aug 18, 2023
2 parents d53217d + 3577bf1 commit fc32a19
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/client/src/context/auth.context.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, useContext, useState } from 'react';
import { ReactNode } from 'react';
import { ReactNode, createContext, useContext, useState } from 'react';
import { passwordResetSchema } from '@root/shared/validators/password.model';
import { loginSchema, singupSchema } from '@root/shared/validators/user.model';
import { Session } from '@supabase/supabase-js';
import z from 'zod';
Expand All @@ -12,6 +12,7 @@ export interface AuthContext {
login: (data: z.infer<typeof loginSchema>) => Promise<any>;
singup: (data: z.infer<typeof singupSchema>) => Promise<any>;
logout: () => Promise<any>;
passwordReset: (data: z.infer<typeof passwordResetSchema>) => Promise<any>;
}

export const AuthContext = createContext<AuthContext | null>(null);
Expand Down Expand Up @@ -47,13 +48,15 @@ export const AuthProvider = ({ children }: AuthProviderProps) => {
},
});
const logout = trpc.auth.logout.useMutation();
const passwordReset = trpc.auth.passwordReset.useMutation();
return (
<AuthContext.Provider
value={{
...state,
login: login.mutateAsync,
logout: logout.mutateAsync,
singup: singup.mutateAsync,
passwordReset: passwordReset.mutateAsync,
}}
>
{children}
Expand Down
10 changes: 10 additions & 0 deletions packages/server/src/routes/auth.route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { passwordResetSchema } from '@root/shared/validators/password.model';
import { loginSchema, singupSchema, validateSchema } from '@root/shared/validators/user.model';
import { TRPCError } from '@trpc/server';
import { z } from 'zod';
Expand All @@ -10,6 +11,15 @@ export const authRouter = router({
return { data, error };
}),

passwordReset: publicProcedure
.input(passwordResetSchema)
.mutation(async ({ input, ctx }) => {
const { email } = input;
const { data, error } = await ctx.supabase.auth.resetPasswordForEmail(email);

return { data, error };
}),

logout: publicProcedure.mutation(async ({ ctx }) => ctx.supabase.auth.signOut()),

singup: publicProcedure.input(singupSchema).mutation(async ({ input, ctx }) => {
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/validators/password.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { z } from 'zod';

export const passwordResetSchema = z.object({
email: z.string().email(),
});

0 comments on commit fc32a19

Please sign in to comment.