← React Intermediate Questions - Set 4 Q37
How do you handle authentication in a React application?
React Intermediate Questions - Set 4
Example
1
2
3
4
function Private({ children }) {
const { token } = useAuth();
return token ? children : <Navigate to="/login" replace />;
}
What to notice
- Token in memory or httpOnly cookie; never trust client-side checks alone — the API must enforce.
← Back to the question list