This commit is contained in:
2025-02-21 15:25:49 -03:00
parent 142e33726d
commit df82a69af0
7 changed files with 129 additions and 47 deletions

View File

@@ -7,7 +7,7 @@ import {
} from 'react'
import * as Auth from 'aws-amplify/auth'
interface AuthContextType {
export type AuthContextType = {
authUser: Auth.FetchUserAttributesOutput | null
signIn: ({
username,
@@ -21,8 +21,14 @@ interface AuthContextType {
const AuthContext = createContext<AuthContextType | null>(null)
export function useAuth() {
return useContext(AuthContext)
export function useAuth(): AuthContextType {
const ctx = useContext(AuthContext)
if (!ctx) {
throw new Error('useAuth must be used within an AuthProvider')
}
return ctx
}
export function AuthProvider({ children }: { children: React.ReactNode }) {