Skip to content

Commit

Permalink
fallback user info when user rejected
Browse files Browse the repository at this point in the history
  • Loading branch information
mister-teddy committed Jun 20, 2024
1 parent bf33cc3 commit 1741d0e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"react-router-dom": "^6.8.2",
"recoil": "^0.7.7",
"swiper": "^9.1.0",
"zmp-sdk": "^2.37.1",
"zmp-sdk": "^2.39.0",
"zmp-ui": "^1.6.0-rc.6"
},
"devDependencies": {
Expand Down
33 changes: 12 additions & 21 deletions src/state.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { atom, selector, selectorFamily } from "recoil";
import {
authorize,
getLocation,
getPhoneNumber,
getSetting,
getUserInfo,
} from "zmp-sdk";
import { getLocation, getPhoneNumber, getUserInfo } from "zmp-sdk";
import logo from "static/logo.png";
import { Category } from "types/category";
import { Product, Variant } from "types/product";
Expand All @@ -17,22 +11,19 @@ import { calcFinalPrice } from "utils/product";
import { wait } from "utils/async";
import categories from "../mock/categories.json";

export const authorizedState = selector({
key: "authorized",
get: async () => {
const { authSetting } = await getSetting({});
if (!authSetting["scope.userInfo"]) {
await authorize({ scopes: [] });
}
},
});

export const userState = selector({
key: "user",
get: async ({ get }) => {
get(authorizedState);
const { userInfo } = await getUserInfo({ avatarType: "small" });
return userInfo;
get: async () => {
try {
const { userInfo } = await getUserInfo({ autoRequestPermission: true });
return userInfo;
} catch (error) {
return {
id: "",
avatar: "",
name: "Người dùng Zalo",
};
}
},
});

Expand Down

0 comments on commit 1741d0e

Please sign in to comment.