Created
January 19, 2021 12:03
-
-
Save effe-megna/78a828b69441f095d9047b06d442f318 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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