From eaa064c385529e7b6b2e51bb0b57e4b83c341b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=E1=BB=93ng=20Ph=C3=A1t?= Date: Fri, 2 Feb 2024 13:55:58 +0700 Subject: [PATCH] update authorize flow --- src/state.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/state.ts b/src/state.ts index cd4bed5..ec1a67d 100644 --- a/src/state.ts +++ b/src/state.ts @@ -1,5 +1,11 @@ import { atom, selector, selectorFamily } from "recoil"; -import { authorize, getLocation, getPhoneNumber, getUserInfo } from "zmp-sdk"; +import { + authorize, + getLocation, + getPhoneNumber, + getSetting, + getUserInfo, +} from "zmp-sdk"; import logo from "static/logo.png"; import { Category } from "types/category"; import { Product, Variant } from "types/product"; @@ -13,10 +19,12 @@ import categories from "../mock/categories.json"; export const authorizedState = selector({ key: "authorized", - get: () => - authorize({ - scopes: ["scope.userLocation", "scope.userPhonenumber"], - }), + get: async () => { + const { authSetting } = await getSetting({}); + if (!authSetting["scope.userInfo"]) { + await authorize({ scopes: [] }); + } + }, }); export const userState = selector({