Skip to content

Commit b3c7e6e

Browse files
committed
ts fix
1 parent 59c54f3 commit b3c7e6e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed
File renamed without changes.

context/AuthContext.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type AuthContextType = {
88
session: Session | null;
99
user: User | null;
1010
};
11-
const AuthContext = createContext<AuthContextType | undefined>(undefined);
11+
const AuthContext = createContext<AuthContextType | null>(null);
1212

1313
export default function AuthContextProvider({ children }: PropsWithChildren) {
1414
const [session, setSession] = useState<Session | null>(null);
@@ -37,4 +37,10 @@ export default function AuthContextProvider({ children }: PropsWithChildren) {
3737
);
3838
}
3939

40-
export const useAuth = () => useContext(AuthContext);
40+
export const useAuth = (): AuthContextType => {
41+
const context = useContext(AuthContext);
42+
if (context === null) {
43+
throw new Error('useAuth must be used within an AuthContextProvider');
44+
}
45+
return context;
46+
};

0 commit comments

Comments
 (0)