@renown/sdk 5.1.0-dev.9 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -487
- package/dist/src/common.d.ts +1 -1
- package/dist/src/common.d.ts.map +1 -1
- package/dist/src/components/RenownLoginAvatar.d.ts +44 -0
- package/dist/src/components/RenownLoginAvatar.d.ts.map +1 -0
- package/dist/src/components/RenownLoginAvatar.js +50 -0
- package/dist/src/components/RenownLoginAvatar.js.map +1 -0
- package/dist/src/components/index.d.ts +3 -7
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -4
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/types.d.ts +12 -0
- package/dist/src/components/types.d.ts.map +1 -0
- package/dist/src/components/types.js +2 -0
- package/dist/src/components/types.js.map +1 -0
- package/dist/src/constants.d.ts +1 -1
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +1 -1
- package/dist/src/constants.js.map +1 -1
- package/dist/src/index.d.ts +1 -8
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/types.d.ts +2 -3
- package/dist/src/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -26
- package/dist/e2e/fixtures/main.d.ts +0 -2
- package/dist/e2e/fixtures/main.d.ts.map +0 -1
- package/dist/e2e/fixtures/main.js +0 -97
- package/dist/e2e/fixtures/main.js.map +0 -1
- package/dist/e2e/fixtures/vite.config.d.ts +0 -3
- package/dist/e2e/fixtures/vite.config.d.ts.map +0 -1
- package/dist/e2e/fixtures/vite.config.js +0 -10
- package/dist/e2e/fixtures/vite.config.js.map +0 -1
- package/dist/e2e/renown-components.spec.d.ts +0 -2
- package/dist/e2e/renown-components.spec.d.ts.map +0 -1
- package/dist/e2e/renown-components.spec.js +0 -155
- package/dist/e2e/renown-components.spec.js.map +0 -1
- package/dist/playwright.config.d.ts +0 -3
- package/dist/playwright.config.d.ts.map +0 -1
- package/dist/playwright.config.js +0 -25
- package/dist/playwright.config.js.map +0 -1
- package/dist/src/assets/assets.d.ts +0 -19
- package/dist/src/assets/renown-hover.svg +0 -17
- package/dist/src/assets/renown-light.svg +0 -15
- package/dist/src/assets/renown-short-hover.png +0 -0
- package/dist/src/assets/renown-short.png +0 -0
- package/dist/src/assets/renown.svg +0 -16
- package/dist/src/components/RenownAuthButton.d.ts +0 -62
- package/dist/src/components/RenownAuthButton.d.ts.map +0 -1
- package/dist/src/components/RenownAuthButton.js +0 -82
- package/dist/src/components/RenownAuthButton.js.map +0 -1
- package/dist/src/components/RenownLoginButton.d.ts +0 -48
- package/dist/src/components/RenownLoginButton.d.ts.map +0 -1
- package/dist/src/components/RenownLoginButton.js +0 -175
- package/dist/src/components/RenownLoginButton.js.map +0 -1
- package/dist/src/components/RenownUserButton.d.ts +0 -66
- package/dist/src/components/RenownUserButton.d.ts.map +0 -1
- package/dist/src/components/RenownUserButton.js +0 -216
- package/dist/src/components/RenownUserButton.js.map +0 -1
- package/dist/src/components/icons.d.ts +0 -25
- package/dist/src/components/icons.d.ts.map +0 -1
- package/dist/src/components/icons.js +0 -24
- package/dist/src/components/icons.js.map +0 -1
- package/dist/src/components/image-data.d.ts +0 -3
- package/dist/src/components/image-data.d.ts.map +0 -1
- package/dist/src/components/image-data.js +0 -4
- package/dist/src/components/image-data.js.map +0 -1
- package/dist/src/hooks/index.d.ts +0 -2
- package/dist/src/hooks/index.d.ts.map +0 -1
- package/dist/src/hooks/index.js +0 -2
- package/dist/src/hooks/index.js.map +0 -1
- package/dist/src/hooks/use-user.d.ts +0 -21
- package/dist/src/hooks/use-user.d.ts.map +0 -1
- package/dist/src/hooks/use-user.js +0 -30
- package/dist/src/hooks/use-user.js.map +0 -1
- package/dist/src/lib/crypto/browser.d.ts +0 -8
- package/dist/src/lib/crypto/browser.d.ts.map +0 -1
- package/dist/src/lib/crypto/browser.js +0 -73
- package/dist/src/lib/crypto/browser.js.map +0 -1
- package/dist/src/lib/crypto/index.d.ts +0 -36
- package/dist/src/lib/crypto/index.d.ts.map +0 -1
- package/dist/src/lib/crypto/index.js +0 -150
- package/dist/src/lib/crypto/index.js.map +0 -1
- package/dist/src/lib/crypto/node.d.ts +0 -8
- package/dist/src/lib/crypto/node.d.ts.map +0 -1
- package/dist/src/lib/crypto/node.js +0 -67
- package/dist/src/lib/crypto/node.js.map +0 -1
- package/dist/src/lib/renown/constants.d.ts +0 -130
- package/dist/src/lib/renown/constants.d.ts.map +0 -1
- package/dist/src/lib/renown/constants.js +0 -40
- package/dist/src/lib/renown/constants.js.map +0 -1
- package/dist/src/lib/renown/did-parser.d.ts +0 -28
- package/dist/src/lib/renown/did-parser.d.ts.map +0 -1
- package/dist/src/lib/renown/did-parser.js +0 -57
- package/dist/src/lib/renown/did-parser.js.map +0 -1
- package/dist/src/lib/renown/index.d.ts +0 -4
- package/dist/src/lib/renown/index.d.ts.map +0 -1
- package/dist/src/lib/renown/index.js +0 -4
- package/dist/src/lib/renown/index.js.map +0 -1
- package/dist/src/lib/renown/utils.d.ts +0 -33
- package/dist/src/lib/renown/utils.d.ts.map +0 -1
- package/dist/src/lib/renown/utils.js +0 -207
- package/dist/src/lib/renown/utils.js.map +0 -1
- package/dist/src/lib/session-storage.d.ts +0 -40
- package/dist/src/lib/session-storage.d.ts.map +0 -1
- package/dist/src/lib/session-storage.js +0 -107
- package/dist/src/lib/session-storage.js.map +0 -1
- package/dist/src/providers/index.d.ts +0 -3
- package/dist/src/providers/index.d.ts.map +0 -1
- package/dist/src/providers/index.js +0 -2
- package/dist/src/providers/index.js.map +0 -1
- package/dist/src/providers/renown-user-provider.d.ts +0 -72
- package/dist/src/providers/renown-user-provider.d.ts.map +0 -1
- package/dist/src/providers/renown-user-provider.js +0 -171
- package/dist/src/providers/renown-user-provider.js.map +0 -1
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
const SESSION_STORAGE_KEYS = {
|
|
3
|
-
USER: "renown_user",
|
|
4
|
-
LOGIN_STATUS: "renown_login_status",
|
|
5
|
-
USER_DID: "renown_user_did",
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Session storage utilities for Renown authentication
|
|
9
|
-
* Stores user data in sessionStorage to persist across page reloads
|
|
10
|
-
* but clears when the browser session ends
|
|
11
|
-
*/
|
|
12
|
-
export class SessionStorageManager {
|
|
13
|
-
/**
|
|
14
|
-
* Store user authentication data in sessionStorage
|
|
15
|
-
*/
|
|
16
|
-
static setUserData(userData) {
|
|
17
|
-
if (typeof window === "undefined")
|
|
18
|
-
return;
|
|
19
|
-
try {
|
|
20
|
-
sessionStorage.setItem(SESSION_STORAGE_KEYS.USER, JSON.stringify(userData.user));
|
|
21
|
-
sessionStorage.setItem(SESSION_STORAGE_KEYS.USER_DID, userData.userDid);
|
|
22
|
-
sessionStorage.setItem(SESSION_STORAGE_KEYS.LOGIN_STATUS, userData.loginStatus);
|
|
23
|
-
sessionStorage.setItem("renown_timestamp", userData.timestamp.toString());
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
console.error("Failed to store user data in sessionStorage:", error);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Retrieve user authentication data from sessionStorage
|
|
31
|
-
*/
|
|
32
|
-
static getUserData() {
|
|
33
|
-
if (typeof window === "undefined")
|
|
34
|
-
return null;
|
|
35
|
-
try {
|
|
36
|
-
const userStr = sessionStorage.getItem(SESSION_STORAGE_KEYS.USER);
|
|
37
|
-
const userDid = sessionStorage.getItem(SESSION_STORAGE_KEYS.USER_DID);
|
|
38
|
-
const loginStatus = sessionStorage.getItem(SESSION_STORAGE_KEYS.LOGIN_STATUS);
|
|
39
|
-
const timestampStr = sessionStorage.getItem("renown_timestamp");
|
|
40
|
-
if (!userStr || !userDid || !loginStatus || !timestampStr) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
const user = JSON.parse(userStr);
|
|
44
|
-
const timestamp = parseInt(timestampStr, 10);
|
|
45
|
-
return {
|
|
46
|
-
user,
|
|
47
|
-
userDid,
|
|
48
|
-
loginStatus: loginStatus,
|
|
49
|
-
timestamp,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
console.error("Failed to retrieve user data from sessionStorage:", error);
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Check if user data exists in sessionStorage
|
|
59
|
-
*/
|
|
60
|
-
static hasUserData() {
|
|
61
|
-
if (typeof window === "undefined")
|
|
62
|
-
return false;
|
|
63
|
-
return !!(sessionStorage.getItem(SESSION_STORAGE_KEYS.USER) &&
|
|
64
|
-
sessionStorage.getItem(SESSION_STORAGE_KEYS.USER_DID) &&
|
|
65
|
-
sessionStorage.getItem(SESSION_STORAGE_KEYS.LOGIN_STATUS));
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Clear all user authentication data from sessionStorage
|
|
69
|
-
*/
|
|
70
|
-
static clearUserData() {
|
|
71
|
-
if (typeof window === "undefined")
|
|
72
|
-
return;
|
|
73
|
-
try {
|
|
74
|
-
sessionStorage.removeItem(SESSION_STORAGE_KEYS.USER);
|
|
75
|
-
sessionStorage.removeItem(SESSION_STORAGE_KEYS.USER_DID);
|
|
76
|
-
sessionStorage.removeItem(SESSION_STORAGE_KEYS.LOGIN_STATUS);
|
|
77
|
-
sessionStorage.removeItem("renown_timestamp");
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
console.error("Failed to clear user data from sessionStorage:", error);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Check if stored user data is still valid (not expired)
|
|
85
|
-
* You can implement expiration logic here if needed
|
|
86
|
-
*/
|
|
87
|
-
static isUserDataValid(userData) {
|
|
88
|
-
// For now, we consider session data valid for the entire browser session
|
|
89
|
-
// You can add expiration logic here if needed
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Get the stored user DID for easy re-authentication
|
|
94
|
-
*/
|
|
95
|
-
static getStoredUserDid() {
|
|
96
|
-
if (typeof window === "undefined")
|
|
97
|
-
return null;
|
|
98
|
-
try {
|
|
99
|
-
return sessionStorage.getItem(SESSION_STORAGE_KEYS.USER_DID);
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
console.error("Failed to get stored user DID:", error);
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=session-storage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session-storage.js","sourceRoot":"","sources":["../../../src/lib/session-storage.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAIb,MAAM,oBAAoB,GAAG;IAC3B,IAAI,EAAE,aAAa;IACnB,YAAY,EAAE,qBAAqB;IACnC,QAAQ,EAAE,iBAAiB;CACnB,CAAC;AASX;;;;GAIG;AACH,MAAM,OAAO,qBAAqB;IAChC;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,QAAyB;QAC1C,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAE1C,IAAI,CAAC;YACH,cAAc,CAAC,OAAO,CACpB,oBAAoB,CAAC,IAAI,EACzB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAC9B,CAAC;YACF,cAAc,CAAC,OAAO,CAAC,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;YACxE,cAAc,CAAC,OAAO,CACpB,oBAAoB,CAAC,YAAY,EACjC,QAAQ,CAAC,WAAW,CACrB,CAAC;YACF,cAAc,CAAC,OAAO,CAAC,kBAAkB,EAAE,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC5E,CAAC;QAAC,OAAO,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AAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { IConnectCrypto } from "../crypto/index.js";
|
|
2
|
-
import type { LoginStatus, User } from "../lib/renown/index.js";
|
|
3
|
-
import type { IRenown } from "../types.js";
|
|
4
|
-
export interface RenownUserContextValue {
|
|
5
|
-
/** Current authenticated user, null if not authenticated */
|
|
6
|
-
user: User | null;
|
|
7
|
-
/** Current login status */
|
|
8
|
-
loginStatus: LoginStatus;
|
|
9
|
-
/** Whether auth operations are in progress */
|
|
10
|
-
isLoading: boolean;
|
|
11
|
-
/** Whether the user system has been initialized */
|
|
12
|
-
isInitialized: boolean;
|
|
13
|
-
/** Login with optional DID (defaults to connectCrypto DID) */
|
|
14
|
-
login: (userDid?: string) => Promise<void>;
|
|
15
|
-
/** Logout the current user */
|
|
16
|
-
logout: () => Promise<void>;
|
|
17
|
-
/** Open Renown portal for authentication */
|
|
18
|
-
openRenown: () => void;
|
|
19
|
-
/** ConnectCrypto instance for cryptographic operations */
|
|
20
|
-
connectCrypto: IConnectCrypto | null;
|
|
21
|
-
/** Renown SDK instance */
|
|
22
|
-
renown: IRenown | null;
|
|
23
|
-
}
|
|
24
|
-
export declare const RenownUserContext: import("react").Context<RenownUserContextValue | null>;
|
|
25
|
-
interface RenownUserProviderProps {
|
|
26
|
-
children: React.ReactNode;
|
|
27
|
-
/**
|
|
28
|
-
* Renown service URL
|
|
29
|
-
* @default 'https://www.renown.id'
|
|
30
|
-
*/
|
|
31
|
-
renownUrl?: string;
|
|
32
|
-
/**
|
|
33
|
-
* Network ID (e.g., 'eip155')
|
|
34
|
-
* @default 'eip155'
|
|
35
|
-
*/
|
|
36
|
-
networkId?: string;
|
|
37
|
-
/**
|
|
38
|
-
* Chain ID (e.g., '1' for Ethereum mainnet)
|
|
39
|
-
* @default '1'
|
|
40
|
-
*/
|
|
41
|
-
chainId?: string;
|
|
42
|
-
/**
|
|
43
|
-
* Custom loading component shown during initialization
|
|
44
|
-
* If not provided, renders children immediately (no loading screen)
|
|
45
|
-
*/
|
|
46
|
-
loadingComponent?: React.ReactNode;
|
|
47
|
-
/**
|
|
48
|
-
* Custom error component shown if initialization fails
|
|
49
|
-
* Receives the error and a retry function
|
|
50
|
-
*/
|
|
51
|
-
errorComponent?: (error: Error, retry: () => void) => React.ReactNode;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* RenownUserProvider - Central user provider for Renown
|
|
55
|
-
*
|
|
56
|
-
* Automatically initializes the Renown SDK and provides user state.
|
|
57
|
-
* Handles initialization, login, logout, and session management.
|
|
58
|
-
*
|
|
59
|
-
* Usage:
|
|
60
|
-
* ```tsx
|
|
61
|
-
* // Wrap your app
|
|
62
|
-
* <RenownUserProvider renownUrl="https://www.renown.id">
|
|
63
|
-
* <YourApp />
|
|
64
|
-
* </RenownUserProvider>
|
|
65
|
-
*
|
|
66
|
-
* // In any component
|
|
67
|
-
* const { user, login, logout } = useUser()
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
export declare function RenownUserProvider({ children, renownUrl, networkId, chainId, loadingComponent, errorComponent, }: RenownUserProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
71
|
-
export {};
|
|
72
|
-
//# sourceMappingURL=renown-user-provider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renown-user-provider.d.ts","sourceRoot":"","sources":["../../../src/providers/renown-user-provider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGzD,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO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|
1
|
-
"use client";
|
|
2
|
-
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useCallback, useEffect, useState } from "react";
|
|
4
|
-
import { BrowserKeyStorage, ConnectCrypto } from "../crypto/index.js";
|
|
5
|
-
import { initRenown } from "../init.browser.js";
|
|
6
|
-
import { fetchProfileDataForUser, handleRenownReturn, openRenown as openRenownPortal, login as renownLogin, logout as renownLogout, } from "../lib/renown/index.js";
|
|
7
|
-
import { SessionStorageManager } from "../lib/session-storage.js";
|
|
8
|
-
export const RenownUserContext = createContext(null);
|
|
9
|
-
/**
|
|
10
|
-
* RenownUserProvider - Central user provider for Renown
|
|
11
|
-
*
|
|
12
|
-
* Automatically initializes the Renown SDK and provides user state.
|
|
13
|
-
* Handles initialization, login, logout, and session management.
|
|
14
|
-
*
|
|
15
|
-
* Usage:
|
|
16
|
-
* ```tsx
|
|
17
|
-
* // Wrap your app
|
|
18
|
-
* <RenownUserProvider renownUrl="https://www.renown.id">
|
|
19
|
-
* <YourApp />
|
|
20
|
-
* </RenownUserProvider>
|
|
21
|
-
*
|
|
22
|
-
* // In any component
|
|
23
|
-
* const { user, login, logout } = useUser()
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export function RenownUserProvider({ children, renownUrl = "https://www.renown.id", networkId = "eip155", chainId = "1", loadingComponent, errorComponent, }) {
|
|
27
|
-
const [user, setUser] = useState(null);
|
|
28
|
-
const [loginStatus, setLoginStatus] = useState("initial");
|
|
29
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
30
|
-
const [isInitialized, setIsInitialized] = useState(false);
|
|
31
|
-
const [initError, setInitError] = useState(null);
|
|
32
|
-
const [connectCrypto, setConnectCrypto] = useState(null);
|
|
33
|
-
const [renown, setRenown] = useState(null);
|
|
34
|
-
// Initialize auth system
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
const init = async () => {
|
|
37
|
-
try {
|
|
38
|
-
if (typeof window === "undefined") {
|
|
39
|
-
setIsInitialized(true);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
// Initialize SDK if not already initialized
|
|
43
|
-
if (!window.renown || !window.connectCrypto) {
|
|
44
|
-
// Initialize ConnectCrypto with browser key storage
|
|
45
|
-
const cryptoInstance = new ConnectCrypto(new BrowserKeyStorage());
|
|
46
|
-
// Initialize Renown SDK
|
|
47
|
-
const renownInstance = initRenown(await cryptoInstance.did(), networkId, renownUrl);
|
|
48
|
-
// Attach to window for global access
|
|
49
|
-
window.renown = renownInstance;
|
|
50
|
-
window.connectCrypto = cryptoInstance;
|
|
51
|
-
// Save to state
|
|
52
|
-
setConnectCrypto(cryptoInstance);
|
|
53
|
-
setRenown(renownInstance);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
// Use existing instances from window
|
|
57
|
-
setConnectCrypto(window.connectCrypto);
|
|
58
|
-
setRenown(window.renown);
|
|
59
|
-
}
|
|
60
|
-
// Check for stored session first
|
|
61
|
-
const storedUserData = SessionStorageManager.getUserData();
|
|
62
|
-
if (storedUserData &&
|
|
63
|
-
SessionStorageManager.isUserDataValid(storedUserData)) {
|
|
64
|
-
// Restore user from stored session
|
|
65
|
-
const userWithProfile = await fetchProfileDataForUser(storedUserData.user);
|
|
66
|
-
setUser(userWithProfile);
|
|
67
|
-
setLoginStatus("authorized");
|
|
68
|
-
setIsInitialized(true);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
// Handle return from Renown authentication
|
|
72
|
-
await handleRenownReturn();
|
|
73
|
-
// Check if user is already logged in
|
|
74
|
-
let currentUser = window.renown.user instanceof Function
|
|
75
|
-
? window.renown.user()
|
|
76
|
-
: window.renown.user;
|
|
77
|
-
currentUser =
|
|
78
|
-
currentUser instanceof Promise ? await currentUser : currentUser;
|
|
79
|
-
if (currentUser) {
|
|
80
|
-
// Fetch profile data for the logged-in user
|
|
81
|
-
const userWithProfile = await fetchProfileDataForUser(currentUser);
|
|
82
|
-
setUser(userWithProfile);
|
|
83
|
-
setLoginStatus("authorized");
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
setLoginStatus("not-authorized");
|
|
87
|
-
}
|
|
88
|
-
setIsInitialized(true);
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
console.error("Failed to initialize authentication:", error);
|
|
92
|
-
setInitError(error);
|
|
93
|
-
setLoginStatus("not-authorized");
|
|
94
|
-
// Still set as initialized to prevent infinite loading
|
|
95
|
-
setIsInitialized(true);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
init();
|
|
99
|
-
}, [renownUrl, networkId, chainId]);
|
|
100
|
-
// Login handler
|
|
101
|
-
const login = useCallback(async (userDid) => {
|
|
102
|
-
if (typeof window === "undefined")
|
|
103
|
-
return;
|
|
104
|
-
const renown = window.renown;
|
|
105
|
-
const connectCrypto = window.connectCrypto;
|
|
106
|
-
if (!renown || !connectCrypto) {
|
|
107
|
-
console.error("Renown or ConnectCrypto not available");
|
|
108
|
-
setLoginStatus("not-authorized");
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
try {
|
|
112
|
-
setIsLoading(true);
|
|
113
|
-
setLoginStatus("checking");
|
|
114
|
-
const did = userDid || (await connectCrypto.did());
|
|
115
|
-
// Perform login
|
|
116
|
-
const loggedInUser = await renownLogin(did, renown, connectCrypto);
|
|
117
|
-
if (loggedInUser) {
|
|
118
|
-
// Fetch profile data and update state
|
|
119
|
-
const userWithProfile = await fetchProfileDataForUser(loggedInUser);
|
|
120
|
-
setUser(userWithProfile);
|
|
121
|
-
setLoginStatus("authorized");
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
setLoginStatus("not-authorized");
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
console.error("Login failed:", error);
|
|
129
|
-
setLoginStatus("not-authorized");
|
|
130
|
-
}
|
|
131
|
-
finally {
|
|
132
|
-
setIsLoading(false);
|
|
133
|
-
}
|
|
134
|
-
}, []);
|
|
135
|
-
// Logout handler
|
|
136
|
-
const logout = useCallback(async () => {
|
|
137
|
-
try {
|
|
138
|
-
await renownLogout();
|
|
139
|
-
setUser(null);
|
|
140
|
-
setLoginStatus("not-authorized");
|
|
141
|
-
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
console.error("Logout failed:", error);
|
|
144
|
-
}
|
|
145
|
-
}, []);
|
|
146
|
-
// Open Renown portal
|
|
147
|
-
const openRenown = useCallback(() => {
|
|
148
|
-
openRenownPortal();
|
|
149
|
-
}, []);
|
|
150
|
-
// Show loading state while initializing
|
|
151
|
-
if (!isInitialized && loadingComponent) {
|
|
152
|
-
return _jsx(_Fragment, { children: loadingComponent });
|
|
153
|
-
}
|
|
154
|
-
// Show error state if initialization failed
|
|
155
|
-
if (initError && errorComponent) {
|
|
156
|
-
return _jsx(_Fragment, { children: errorComponent(initError, () => window.location.reload()) });
|
|
157
|
-
}
|
|
158
|
-
const value = {
|
|
159
|
-
user,
|
|
160
|
-
loginStatus,
|
|
161
|
-
isLoading,
|
|
162
|
-
isInitialized,
|
|
163
|
-
login,
|
|
164
|
-
logout,
|
|
165
|
-
openRenown,
|
|
166
|
-
connectCrypto,
|
|
167
|
-
renown,
|
|
168
|
-
};
|
|
169
|
-
return _jsx(RenownUserContext.Provider, { value: value, children: children });
|
|
170
|
-
}
|
|
171
|
-
//# sourceMappingURL=renown-user-provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renown-user-provider.js","sourceRoot":"","sources":["../../../src/providers/renown-user-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAExE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EACL,uBAAuB,E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