@@ -103,10 +117,14 @@ onMounted(() => {
v-for="certificate in data?.result?.creditOffsetCertificates?.nodes"
:key="certificate.id"
>
-
+
{
closeSelectWalletModal();
};
-const disconnectWallet = () => {
- localStorage.removeItem("address");
- localStorage.removeItem("wallet");
- location.reload();
-};
-
const copyAddress = async () => {
await navigator.clipboard.writeText(address.value ?? "");
toast.success("Address copied to clipboard");
diff --git a/frontend/marketplace/src/main.ts b/frontend/marketplace/src/main.ts
index 0169ef2e..f472bd50 100644
--- a/frontend/marketplace/src/main.ts
+++ b/frontend/marketplace/src/main.ts
@@ -37,7 +37,7 @@ const app = createApp(App);
const logtoConfig: LogtoConfig = {
endpoint: LOGTO_ENDPOINT,
appId: LOGTO_APP_ID,
- scopes: ["email"],
+ scopes: ["email", "custom_data"],
resources: [PC_BACKEND_ENDPOINT],
};
diff --git a/frontend/marketplace/src/stores/auth.ts b/frontend/marketplace/src/stores/auth.ts
index bd504331..81549a46 100644
--- a/frontend/marketplace/src/stores/auth.ts
+++ b/frontend/marketplace/src/stores/auth.ts
@@ -1,38 +1,62 @@
-import { ref, watch, type Ref } from "vue";
+import { type Ref, ref, watch, computed } from "vue";
import { WEB_ENDPOINT } from "@/config/config";
-import { useLogto, type UserInfoResponse } from "@logto/vue";
+import { type UserInfoResponse, useLogto } from "@logto/vue";
import { useRedirectAfterLoginUrl } from "@/utils/redirectAfterLoginUrl";
+interface AuthCustomData {
+ walletAddress: string;
+}
+
+interface CustomUserInfoResponse extends UserInfoResponse {
+ custom_data: AuthCustomData;
+}
+
+type Logto = ReturnType;
+interface CustomLogto extends Logto {
+ fetchUserInfo: () => Promise;
+}
+
export interface Auth {
- user: Ref;
+ user: Ref;
error: Ref;
isAuthenticated: Ref;
handleSignIn: () => void;
handleSignOut: () => void;
- fetchUser: () => Promise;
+ fetchUser: () => Promise;
getAccessToken: (resource?: string) => Promise;
+ walletAddress: Ref;
}
export const useAuth = (): Auth => {
const {
- signIn: logToSignIn,
- signOut: logToSignOut,
- isAuthenticated: logToIsAuthenticated,
- fetchUserInfo: logToFetchUserInfo,
- error: logToError,
- getAccessToken: logToGetAccessToken,
- } = useLogto();
+ signIn: logtoSignIn,
+ signOut: logtoSignOut,
+ isAuthenticated: logtoIsAuthenticated,
+ fetchUserInfo: logtoFetchUserInfo,
+ error: logtoError,
+ getAccessToken: logtoGetAccessToken,
+ } = useLogto() as CustomLogto;
- const error = ref[>(logToError);
- const user = ref(undefined);
- const isAuthenticated = ref(logToIsAuthenticated);
- const getAccessToken = logToGetAccessToken;
+ const error = ref][>(logtoError);
+ const user = ref(undefined);
+ const isAuthenticated = ref(logtoIsAuthenticated);
+ const getAccessToken = logtoGetAccessToken;
+ const walletAddress = computed(() => {
+ if (user.value) {
+ try {
+ return user.value.custom_data.walletAddress;
+ } catch (error) {
+ throw new Error("User does not have wallet address");
+ }
+ }
+ return undefined;
+ });
watch(
isAuthenticated,
async (newValue) => {
if (newValue) {
- user.value = await logToFetchUserInfo();
+ user.value = await logtoFetchUserInfo();
} else {
user.value = undefined;
}
@@ -42,15 +66,15 @@ export const useAuth = (): Auth => {
const handleSignIn = () => {
useRedirectAfterLoginUrl().set();
- logToSignIn(`${WEB_ENDPOINT}/callback`);
+ logtoSignIn(`${WEB_ENDPOINT}/callback`);
};
const handleSignOut = () => {
- logToSignOut(WEB_ENDPOINT);
+ logtoSignOut(WEB_ENDPOINT);
};
- const fetchUser = async (): Promise => {
- return await logToFetchUserInfo();
+ const fetchUser = async (): Promise => {
+ return await logtoFetchUserInfo();
};
return {
@@ -61,5 +85,6 @@ export const useAuth = (): Auth => {
handleSignOut,
fetchUser,
getAccessToken,
+ walletAddress,
};
};
diff --git a/frontend/marketplace/src/utils/notifyer.ts b/frontend/marketplace/src/utils/notifyer.ts
index 19745982..26e4193a 100644
--- a/frontend/marketplace/src/utils/notifyer.ts
+++ b/frontend/marketplace/src/utils/notifyer.ts
@@ -1,9 +1,9 @@
-import { toast } from 'vue3-toastify';
+import { toast } from "vue3-toastify";
export const useNotifyer = () => {
const notifyer = toast;
return {
notifyer,
- }
-}
+ };
+};
diff --git a/frontend/marketplace/src/utils/wallet-utils.ts b/frontend/marketplace/src/utils/wallet-utils.ts
index 26cda1db..33a4bb86 100644
--- a/frontend/marketplace/src/utils/wallet-utils.ts
+++ b/frontend/marketplace/src/utils/wallet-utils.ts
@@ -56,3 +56,9 @@ export async function formatDenom(denom: string): Promise {
denom = denom.slice(1);
return denom.toUpperCase();
}
+
+export const disconnectWallet = () => {
+ localStorage.removeItem("address");
+ localStorage.removeItem("wallet");
+ location.reload();
+};
]