import * as React from 'react'; export interface Me { username: string; admin: boolean; } export interface AuthenticationContextValue { refresh: () => void; signIn: (accessToken: string) => void; signOut: () => void; me?: Me; } const AuthenticationContextDefaultValue = {} as AuthenticationContextValue; export const AuthenticationContext = React.createContext( AuthenticationContextDefaultValue ); export interface AuthenticationContextProps { authenticationContext: AuthenticationContextValue; } export function withAuthenticationContext( Component: React.ComponentType ) { return class extends React.Component< Omit > { render() { return ( {(authenticationContext) => ( )} ); } }; } export interface AuthenticatedContextValue extends AuthenticationContextValue { me: Me; } const AuthenticatedContextDefaultValue = {} as AuthenticatedContextValue; export const AuthenticatedContext = React.createContext( AuthenticatedContextDefaultValue ); export interface AuthenticatedContextProps { authenticatedContext: AuthenticatedContextValue; } export function withAuthenticatedContext( Component: React.ComponentType ) { return class extends React.Component< Omit > { render() { return ( {(authenticatedContext) => ( )} ); } }; }