@eviljs/reactx
Version:
Awesome React UI Widgets
17 lines (16 loc) • 673 B
JavaScript
import { AuthTokenState } from '@eviljs/react/auth';
export function AuthBarrier(props) {
const { children, fallback, progress, tokenState } = props;
switch (tokenState) {
// Fast path, from the most common to least common.
case AuthTokenState.Valid:
return children; // Token has been verified and is valid. We can safely continue.
case AuthTokenState.Missing:
case AuthTokenState.Invalid:
return fallback; // Token is missing or invalid.
case AuthTokenState.Validating:
return progress; // We are waiting the response from the server.
case undefined:
return;
}
}