eletrotupi / tcc/ commit / 02a7abe

frontend/context: introduce update internal auth user method

Pedro Lucas Porcellis porcellis@eletrotupi.com · 5 months ago 02a7abe0f5af9cd206353ebb7cd528461b95aeb7 Browse files
Parents 1720731
Changed files
1
Additions
+11
Deletions
0
frontend/context/AuthContext.tsx
1 1
import React, { createContext, useContext, useEffect, useState } from 'react';
2 2
import { apiClient, User } from '@/lib/api';
3 3

4 4
interface AuthProviderProps {
5 5
  children: React.ReactNode;
7 7

8 8
interface AuthContextType {
9 9
  user: User | null;
10 10
  isLoading: boolean;
11 11
  isAuthenticated: boolean;
12 +
  updateAuthUser: (user: {
13 +
    firstName: string;
14 +
    lastName?: string;
15 +
    email: string;
16 +
    updatedAt: date;
17 +
  }) => void;
12 18
  login: (email: string, password: string) => Promise<void>;
13 19
  signup: (userData: {
14 20
    firstName: string;
15 21
    lastName?: string;
16 22
    email: string;
111 117

112 118
  const resetPassword = async (token: string, password: string) => {
113 119
    await apiClient.resetPassword(token, password);
114 120
  };
115 121

122 +
  const updateAuthUser = (user) => {
123 +
    setUser(user);
124 +
  }
125 +

116 126
  const value: AuthContextType = {
117 127
    user,
118 128
    isLoading,
119 129
    isAuthenticated,
120 130
    login,
121 131
    signup,
122 132
    logout,
123 133
    forgotPassword,
124 134
    resetPassword,
135 +
    updateAuthUser
125 136
  };
126 137

127 138
  return (
128 139
    <AuthContext.Provider value={value}>
129 140
      {children}
130 141
    </AuthContext.Provider>
131 142
  );
132 143
}