Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
Brought over 'userID' function from easybasejs
Browse files Browse the repository at this point in the history
  • Loading branch information
dilan-dio4 committed Jun 7, 2021
1 parent a565191 commit b5534d3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion example/src/ProjectUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export default function ProjectUser() {
onSignIn,
db,
forgotPassword,
forgotPasswordConfirm
forgotPasswordConfirm,
userID
} = useEasybase();

const onSignUpClick = async () => {
Expand Down Expand Up @@ -101,6 +102,7 @@ export default function ProjectUser() {
return (
<div style={{ display: "flex", width: '100vw', height: '90vh', justifyContent: 'center', alignItems: 'center', flexDirection: "column" }}>
<div style={{ display: "flex", flexDirection: "column", backgroundColor: "#BBB", padding: 40, borderRadius: 5 }}>
<h5>User ID: {userID()}</h5>
<button className="btn green m-4" onClick={onUserAttrsClick}><span>Get user attrs</span></button>
<button className="btn orange m-4" onClick={signOut}><span>Sign Out</span></button>
<button className="btn orange m-4" onClick={addUserRecord}><span>Add User Record</span></button>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"native"
],
"dependencies": {
"easybasejs": "^4.2.15",
"easybasejs": "^4.2.17",
"easyqb": "^1.0.20",
"fast-deep-equal": "^3.1.3",
"object-observer": "^4.0.3",
Expand Down
10 changes: 7 additions & 3 deletions src/EasybaseProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const {
signIn,
signOut,
forgotPassword,
forgotPasswordConfirm
forgotPasswordConfirm,
userID
} = authFactory(g);

const { log } = utilsFactory(g);
Expand Down Expand Up @@ -144,12 +145,14 @@ const EasybaseProvider = ({ children, ebconfig, options }: EasybaseProviderProps

const refreshTokenRes = await tokenPost(POST_TYPES.REQUEST_TOKEN, {
refreshToken: g.refreshToken,
token: g.token
token: g.token,
getUserID: true
});

if (refreshTokenRes.success) {
clearTimeout(fallbackMount);
g.token = refreshTokenRes.data.token;
g.userID = refreshTokenRes.data.userID;
await cache.setCacheTokens(g, cookieName);
setUserSignedIn(true);
} else {
Expand Down Expand Up @@ -569,7 +572,8 @@ const EasybaseProvider = ({ children, ebconfig, options }: EasybaseProviderProps
e,
useReturn,
forgotPassword,
forgotPasswordConfirm
forgotPasswordConfirm,
userID
}

return (
Expand Down
7 changes: 7 additions & 0 deletions src/types/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface ContextValue {
onSignIn(callback: () => void): void;
/**
* Check if a user is currently signed in.
* @return {boolean} Is a user signed in.
*/
isUserSignedIn(): boolean;
/**
Expand Down Expand Up @@ -283,6 +284,11 @@ export interface ContextValue {
* @return {Promise<StatusResponse>} A StatusResponse corresponding to the successful setting of a new password
*/
forgotPasswordConfirm(code: string, username: string, newPassword: string): Promise<StatusResponse>
/**
* Retrieve the currently signed-in user's ID.
* @return {string | undefined} The currently signed-in user's ID (username), otherwise undefined.
*/
userID(): string | undefined;
}

/**
Expand Down Expand Up @@ -447,4 +453,5 @@ export interface Globals {
instance: string;
mounted: boolean;
newTokenCallback(): void;
userID: string | undefined;
}

0 comments on commit b5534d3

Please sign in to comment.