Skip to content

Commit dc1c0f0

Browse files
author
sw-yx
committed
dont use ref
1 parent afd533b commit dc1c0f0

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-netlify-identity",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "use netlify identity with react",
55
"author": "sw-yx",
66
"license": "MIT",

src/index.tsx

+10-12
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ export function useNetlifyIdentity(
1717
domain: string,
1818
onAuthChange: authChangeParam = () => {}
1919
) {
20-
const authRef = React.useRef(
21-
new GoTrue({
22-
APIUrl: `${domain}/.netlify/identity`,
23-
setCookie: true
24-
})
25-
);
20+
const goTrueInstance = new GoTrue({
21+
APIUrl: `${domain}/.netlify/identity`,
22+
setCookie: true
23+
});
2624

2725
const [user, setUser] = React.useState<User | undefined>(undefined);
2826
const _setUser = (_user: User | undefined) => {
@@ -33,13 +31,13 @@ export function useNetlifyIdentity(
3331
/******* OPERATIONS */
3432
// make sure the Registration preferences under Identity settings in your Netlify dashboard are set to Open.
3533
const signupUser = (email: string, password: string, data: Object) =>
36-
authRef.current.signup(email, password, data).then(_setUser); // TODO: make setUser optional?
34+
goTrueInstance.signup(email, password, data).then(_setUser); // TODO: make setUser optional?
3735
const loginUser = (email: string, password: string) =>
38-
authRef.current.login(email, password).then(_setUser);
36+
goTrueInstance.login(email, password).then(_setUser);
3937
const requestPasswordRecovery = (email: string) =>
40-
authRef.current.requestPasswordRecovery(email);
38+
goTrueInstance.requestPasswordRecovery(email);
4139
const recoverAccount = (token: string, remember?: boolean | undefined) =>
42-
authRef.current.recover(token, remember);
40+
goTrueInstance.recover(token, remember);
4341
const updateUser = (fields: Object) => {
4442
if (user == null) {
4543
throw new Error('No current user found - are you logged in?');
@@ -90,7 +88,7 @@ export function useNetlifyIdentity(
9088
if (hash.slice(0, 19) === 'confirmation_token=') {
9189
// we are in a confirmation!
9290
const token = hash.slice(19);
93-
authRef.current
91+
goTrueInstance
9492
.confirm(token)
9593
.then(_setUser)
9694
.catch(console.error);
@@ -116,7 +114,7 @@ export function useNetlifyIdentity(
116114
updateUser,
117115
getFreshJWT,
118116
authedFetch,
119-
_authRef: authRef,
117+
_goTrueInstance: goTrueInstance,
120118
_domain: domain
121119
};
122120
}

0 commit comments

Comments
 (0)