File tree Expand file tree Collapse file tree 2 files changed +43
-20
lines changed Expand file tree Collapse file tree 2 files changed +43
-20
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { useForm } from 'react-hook-form';
6
6
import { toast } from 'sonner' ;
7
7
8
8
import { authClient } from '@/lib/auth/client' ;
9
+ import { orpc } from '@/lib/orpc/client' ;
9
10
10
11
import {
11
12
Form ,
@@ -41,26 +42,23 @@ export const ChangeNameDrawer = (props: { children: ReactNode }) => {
41
42
} ,
42
43
} ) ;
43
44
44
- const updateUser = useMutation ( {
45
- mutationFn : async ( variables : { name : string } ) => {
46
- await authClient . updateUser ( {
47
- name : variables . name ,
48
- } ) ;
49
- await session . refetch ( ) ;
50
- } ,
51
- onSuccess : ( ) => {
52
- toast . success ( 'Name updated' ) ;
53
- form . reset ( ) ;
54
- router . navigate ( {
55
- replace : true ,
56
- to : '.' ,
57
- search : {
58
- state : '' ,
59
- } ,
60
- } ) ;
61
- } ,
62
- onError : ( ) => toast . error ( 'Failed to update your name' ) ,
63
- } ) ;
45
+ const updateUser = useMutation (
46
+ orpc . account . updateInfo . mutationOptions ( {
47
+ onSuccess : async ( ) => {
48
+ await session . refetch ( ) ;
49
+ toast . success ( 'Name updated' ) ;
50
+ form . reset ( ) ;
51
+ router . navigate ( {
52
+ replace : true ,
53
+ to : '.' ,
54
+ search : {
55
+ state : '' ,
56
+ } ,
57
+ } ) ;
58
+ } ,
59
+ onError : ( ) => toast . error ( 'Failed to update your name' ) ,
60
+ } )
61
+ ) ;
64
62
65
63
return (
66
64
< ResponsiveDrawer
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { z } from 'zod';
2
2
3
3
import { zFormFieldsOnboarding } from '@/features/auth/schema' ;
4
4
import { protectedProcedure } from '@/server/orpc' ;
5
+ import { zUser } from '@/features/user/schema' ;
5
6
6
7
const tags = [ 'account' ] ;
7
8
@@ -26,4 +27,28 @@ export default {
26
27
} ,
27
28
} ) ;
28
29
} ) ,
30
+
31
+ updateInfo : protectedProcedure ( {
32
+ permission : null ,
33
+ } )
34
+ . route ( {
35
+ method : 'POST' ,
36
+ path : '/account/info' ,
37
+ tags,
38
+ } )
39
+ . input (
40
+ zUser ( ) . pick ( {
41
+ name : true ,
42
+ } )
43
+ )
44
+ . output ( z . void ( ) )
45
+ . handler ( async ( { context, input } ) => {
46
+ context . logger . info ( 'Update user' ) ;
47
+ await context . db . user . update ( {
48
+ where : { id : context . user . id } ,
49
+ data : {
50
+ name : input . name ?? '' ,
51
+ } ,
52
+ } ) ;
53
+ } ) ,
29
54
} ;
You can’t perform that action at this time.
0 commit comments