Skip to content

Commit 77099a3

Browse files
author
sw-yx
committedMay 30, 2019
change settings api and remove useMemo call
1 parent 964b3ae commit 77099a3

File tree

2 files changed

+2642
-73
lines changed

2 files changed

+2642
-73
lines changed
 

‎example/yarn.lock

+2,622-65
Large diffs are not rendered by default.

‎src/index.tsx

+20-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ type authChangeParam = (user?: User) => string | void;
88
export type Settings = Settings;
99
export type User = User;
1010

11+
const defaultSettings = {
12+
autoconfirm: false,
13+
disable_signup: false,
14+
external: {
15+
bitbucket: false,
16+
email: true,
17+
facebook: false,
18+
github: false,
19+
gitlab: false,
20+
google: false,
21+
},
22+
};
23+
1124
export type ReactNetlifyIdentityAPI = {
1225
user: User | undefined;
1326
/** not meant for normal use! you should mostly use one of the other exported methods to update the user instance */
@@ -47,7 +60,7 @@ export type ReactNetlifyIdentityAPI = {
4760
provider: 'bitbucket' | 'github' | 'gitlab' | 'google',
4861
token: string
4962
) => string;
50-
settings: () => Promise<Settings>;
63+
settings: Settings;
5164
};
5265

5366
const [_useIdentityCtx, _IdentityCtxProvider] = createCtx<
@@ -74,10 +87,7 @@ export function IdentityContextProvider({
7487
'. Please check the docs for proper usage or file an issue.'
7588
);
7689
}
77-
const identity = React.useMemo(() => useNetlifyIdentity(url, onAuthChange), [
78-
url,
79-
onAuthChange,
80-
]);
90+
const identity = useNetlifyIdentity(url, onAuthChange);
8191
return (
8292
<_IdentityCtxProvider value={identity}>{children}</_IdentityCtxProvider>
8393
);
@@ -118,9 +128,11 @@ export function useNetlifyIdentity(
118128
};
119129
const acceptInviteExternalUrl = (provider: Provider, token: string) =>
120130
goTrueInstance.acceptInviteExternalUrl(provider, token);
121-
const settings: () => Promise<Settings> = goTrueInstance.settings.bind(
122-
goTrueInstance
123-
);
131+
const _settings = goTrueInstance.settings.bind(goTrueInstance);
132+
const [settings, setSettings] = React.useState<Settings>(defaultSettings);
133+
React.useEffect(() => {
134+
_settings().then(x => setSettings(x));
135+
}, [settings]);
124136

125137
/******* email auth */
126138
const signupUser = (email: string, password: string, data: Object) =>

0 commit comments

Comments
 (0)
Please sign in to comment.