Skip to content

Instantly share code, notes, and snippets.

@effe-megna
Created January 19, 2021 12:03
Show Gist options
  • Select an option

  • Save effe-megna/78a828b69441f095d9047b06d442f318 to your computer and use it in GitHub Desktop.

Select an option

Save effe-megna/78a828b69441f095d9047b06d442f318 to your computer and use it in GitHub Desktop.
interface Functions {
logout: (input: LogoutParams) => Promise<unknown>
userDetails: (input: UserDetailsParams) => Promise<unknown>
}
interface State {
user: unknown
}
interface LogoutParams {}
interface UserDetailsParams {}
interface Configuration {
client_id: string
}
type AuthClient
= Configured
| Loaded
interface Loading {
readonly kind: 'loading'
}
interface Loaded {
readonly kind: 'loaded'
functions: Functions
}
interface Configured {
readonly kind: 'configured'
}
const _logout = (state: State) => async (input: LogoutParams) => { }
const _userDetails = (state: State) => async (input: UserDetailsParams) => { }
const useAuthClient = async (config: Configuration) => {
const state = { user: null }
return {
client: { kind: 'configured' },
loadClient: async (): Promise<AuthClient> => {
return {
kind: 'loaded',
functions: {
logout: _logout(state),
userDetails: _userDetails(state)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment