@replyke/react-js 7.0.0-beta.105 → 7.0.0-beta.107
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/dist/cjs/AccountManager.js +21 -73
- package/dist/cjs/AccountManager.js.map +1 -1
- package/dist/cjs/hooks/useOAuthSignIn.js +58 -113
- package/dist/cjs/hooks/useOAuthSignIn.js.map +1 -1
- package/dist/cjs/index.js +4 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/AccountManager.js +20 -72
- package/dist/esm/AccountManager.js.map +1 -1
- package/dist/esm/hooks/useOAuthSignIn.js +56 -111
- package/dist/esm/hooks/useOAuthSignIn.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,83 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
getAccountMap
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
catch (_b) {
|
|
51
|
-
return [2 /*return*/, null];
|
|
52
|
-
}
|
|
53
|
-
return [2 /*return*/];
|
|
54
|
-
});
|
|
55
|
-
});
|
|
3
|
+
const core_1 = require("@replyke/core");
|
|
4
|
+
const STORAGE_KEY_PREFIX = "replyke-accounts:";
|
|
5
|
+
const webAccountStorage = {
|
|
6
|
+
async getAccountMap(projectId) {
|
|
7
|
+
try {
|
|
8
|
+
const raw = localStorage.getItem(`${STORAGE_KEY_PREFIX}${projectId}`);
|
|
9
|
+
return raw ? JSON.parse(raw) : null;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
56
14
|
},
|
|
57
|
-
setAccountMap
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
(0, core_1.handleError)(error, "Failed to write account map to localStorage");
|
|
65
|
-
}
|
|
66
|
-
return [2 /*return*/];
|
|
67
|
-
});
|
|
68
|
-
});
|
|
15
|
+
async setAccountMap(projectId, map) {
|
|
16
|
+
try {
|
|
17
|
+
localStorage.setItem(`${STORAGE_KEY_PREFIX}${projectId}`, JSON.stringify(map));
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
(0, core_1.handleError)(error, "Failed to write account map to localStorage");
|
|
21
|
+
}
|
|
69
22
|
},
|
|
70
|
-
deleteAccountMap
|
|
71
|
-
|
|
72
|
-
return __generator(this, function (_a) {
|
|
73
|
-
localStorage.removeItem("".concat(STORAGE_KEY_PREFIX).concat(projectId));
|
|
74
|
-
return [2 /*return*/];
|
|
75
|
-
});
|
|
76
|
-
});
|
|
23
|
+
async deleteAccountMap(projectId) {
|
|
24
|
+
localStorage.removeItem(`${STORAGE_KEY_PREFIX}${projectId}`);
|
|
77
25
|
},
|
|
78
26
|
};
|
|
79
27
|
function AccountManager() {
|
|
80
|
-
|
|
28
|
+
const { projectId } = (0, core_1.useProject)();
|
|
81
29
|
(0, core_1.useAccountSync)(webAccountStorage, projectId);
|
|
82
30
|
return null;
|
|
83
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountManager.js","sourceRoot":"","sources":["../../src/AccountManager.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AccountManager.js","sourceRoot":"","sources":["../../src/AccountManager.tsx"],"names":[],"mappings":";;AAAA,wCAAwE;AAGxE,MAAM,kBAAkB,GAAG,mBAAmB,CAAC;AAE/C,MAAM,iBAAiB,GAAoB;IACzC,KAAK,CAAC,aAAa,CAAC,SAAiB;QACnC,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,kBAAkB,GAAG,SAAS,EAAE,CAAC,CAAC;YACtE,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACtC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,SAAiB,EAAE,GAAe;QACpD,IAAI,CAAC;YACH,YAAY,CAAC,OAAO,CAClB,GAAG,kBAAkB,GAAG,SAAS,EAAE,EACnC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CACpB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAA,kBAAW,EAAC,KAAK,EAAE,6CAA6C,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,SAAiB;QACtC,YAAY,CAAC,UAAU,CAAC,GAAG,kBAAkB,GAAG,SAAS,EAAE,CAAC,CAAC;IAC/D,CAAC;CACF,CAAC;AAEF,SAAS,cAAc;IACrB,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,iBAAU,GAAE,CAAC;IACnC,IAAA,qBAAc,EAAC,iBAAiB,EAAE,SAAU,CAAC,CAAC;IAC9C,OAAO,IAAI,CAAC;AACd,CAAC;AAED,kBAAe,cAAc,CAAC"}
|
|
@@ -1,44 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const core_1 = require("@replyke/core");
|
|
5
|
+
const BASE_URL = "https://api.replyke.com/v7";
|
|
42
6
|
/**
|
|
43
7
|
* Web-only hook for OAuth sign-in and identity linking.
|
|
44
8
|
* Uses window.location for redirect-based OAuth flow.
|
|
@@ -55,81 +19,62 @@ var BASE_URL = "https://api.replyke.com/v7";
|
|
|
55
19
|
* useEffect(() => { handleOAuthCallback(); }, []);
|
|
56
20
|
*/
|
|
57
21
|
function useOAuthSignIn() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var _b = (0, react_1.useState)(null), error = _b[0], setError = _b[1];
|
|
22
|
+
const { projectId } = (0, core_1.useProject)();
|
|
23
|
+
const dispatch = (0, core_1.useReplykeDispatch)();
|
|
24
|
+
const accessToken = (0, core_1.useReplykeSelector)(core_1.selectAccessToken);
|
|
25
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
26
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
64
27
|
// Shared helper for both /authorize and /link endpoints
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
headers = {
|
|
85
|
-
"Content-Type": "application/json",
|
|
86
|
-
};
|
|
87
|
-
if (endpoint === "link") {
|
|
88
|
-
headers["Authorization"] = "Bearer ".concat(accessToken);
|
|
89
|
-
}
|
|
90
|
-
return [4 /*yield*/, fetch("".concat(BASE_URL, "/").concat(projectId, "/oauth/").concat(endpoint), {
|
|
91
|
-
method: "POST",
|
|
92
|
-
headers: headers,
|
|
93
|
-
body: JSON.stringify({ provider: provider, redirectAfterAuth: redirect }),
|
|
94
|
-
})];
|
|
95
|
-
case 2:
|
|
96
|
-
response = _a.sent();
|
|
97
|
-
if (!!response.ok) return [3 /*break*/, 4];
|
|
98
|
-
return [4 /*yield*/, response.json()];
|
|
99
|
-
case 3:
|
|
100
|
-
data_1 = _a.sent();
|
|
101
|
-
throw new Error(data_1.error || "Failed to initiate OAuth");
|
|
102
|
-
case 4: return [4 /*yield*/, response.json()];
|
|
103
|
-
case 5:
|
|
104
|
-
data = _a.sent();
|
|
105
|
-
// Redirect browser to provider's authorization page.
|
|
106
|
-
// isLoading intentionally stays true since we're navigating away.
|
|
107
|
-
window.location.href = data.authorizationUrl;
|
|
108
|
-
return [3 /*break*/, 7];
|
|
109
|
-
case 6:
|
|
110
|
-
err_1 = _a.sent();
|
|
111
|
-
setError(err_1.message);
|
|
112
|
-
setIsLoading(false);
|
|
113
|
-
return [3 /*break*/, 7];
|
|
114
|
-
case 7: return [2 /*return*/];
|
|
28
|
+
const startOAuthFlow = (0, react_1.useCallback)(async (endpoint, provider, redirectAfterAuth) => {
|
|
29
|
+
if (!projectId) {
|
|
30
|
+
setError("No projectId available.");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (endpoint === "link" && !accessToken) {
|
|
34
|
+
setError("Must be authenticated to link an OAuth provider.");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
setIsLoading(true);
|
|
38
|
+
setError(null);
|
|
39
|
+
try {
|
|
40
|
+
const redirect = redirectAfterAuth || window.location.href;
|
|
41
|
+
// /authorize is unauthenticated, /link requires the access token
|
|
42
|
+
const headers = {
|
|
43
|
+
"Content-Type": "application/json",
|
|
44
|
+
};
|
|
45
|
+
if (endpoint === "link") {
|
|
46
|
+
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
115
47
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
48
|
+
const response = await fetch(`${BASE_URL}/${projectId}/oauth/${endpoint}`, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers,
|
|
51
|
+
body: JSON.stringify({ provider, redirectAfterAuth: redirect }),
|
|
52
|
+
});
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
const data = await response.json();
|
|
55
|
+
throw new Error(data.error || "Failed to initiate OAuth");
|
|
56
|
+
}
|
|
57
|
+
const data = await response.json();
|
|
58
|
+
// Redirect browser to provider's authorization page.
|
|
59
|
+
// isLoading intentionally stays true since we're navigating away.
|
|
60
|
+
window.location.href = data.authorizationUrl;
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
setError(err.message);
|
|
64
|
+
setIsLoading(false);
|
|
65
|
+
}
|
|
66
|
+
}, [projectId, accessToken]);
|
|
67
|
+
const initiateOAuth = (0, react_1.useCallback)((provider, redirectAfterAuth) => startOAuthFlow("authorize", provider, redirectAfterAuth), [startOAuthFlow]);
|
|
68
|
+
const linkOAuthProvider = (0, react_1.useCallback)((provider, redirectAfterAuth) => startOAuthFlow("link", provider, redirectAfterAuth), [startOAuthFlow]);
|
|
69
|
+
const handleOAuthCallback = (0, react_1.useCallback)(() => {
|
|
125
70
|
// Tokens arrive in the URL fragment (#accessToken=...&refreshToken=...)
|
|
126
71
|
// Errors arrive in query params (?error=...&error_description=...)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
72
|
+
const hash = window.location.hash.substring(1); // Remove leading #
|
|
73
|
+
const fragmentParams = new URLSearchParams(hash);
|
|
74
|
+
const queryParams = new URLSearchParams(window.location.search);
|
|
75
|
+
const fragmentAccessToken = fragmentParams.get("accessToken");
|
|
76
|
+
const refreshToken = fragmentParams.get("refreshToken");
|
|
77
|
+
const oauthError = queryParams.get("error");
|
|
133
78
|
if (oauthError) {
|
|
134
79
|
setError(queryParams.get("error_description") || oauthError);
|
|
135
80
|
// Clean URL
|
|
@@ -139,13 +84,13 @@ function useOAuthSignIn() {
|
|
|
139
84
|
if (fragmentAccessToken && refreshToken) {
|
|
140
85
|
// Store tokens in Redux. The AccountManager (via useAccountSync)
|
|
141
86
|
// will detect the new tokens and persist them to localStorage.
|
|
142
|
-
dispatch((0, core_1.setTokens)({ accessToken: fragmentAccessToken, refreshToken
|
|
87
|
+
dispatch((0, core_1.setTokens)({ accessToken: fragmentAccessToken, refreshToken }));
|
|
143
88
|
dispatch((0, core_1.setInitialized)(true));
|
|
144
89
|
// Fetch user profile so useAccountSync can persist the account.
|
|
145
90
|
// The thunk reads the just-set refresh token from Redux, calls the
|
|
146
91
|
// server, and dispatches setUser + setUserInUserSlice on success.
|
|
147
92
|
if (projectId) {
|
|
148
|
-
dispatch((0, core_1.requestNewAccessTokenThunk)({ projectId
|
|
93
|
+
dispatch((0, core_1.requestNewAccessTokenThunk)({ projectId }));
|
|
149
94
|
}
|
|
150
95
|
// Clean URL (remove fragment with tokens)
|
|
151
96
|
window.history.replaceState({}, "", window.location.pathname);
|
|
@@ -153,7 +98,7 @@ function useOAuthSignIn() {
|
|
|
153
98
|
}
|
|
154
99
|
return false;
|
|
155
100
|
}, [dispatch, projectId]);
|
|
156
|
-
return { initiateOAuth
|
|
101
|
+
return { initiateOAuth, linkOAuthProvider, handleOAuthCallback, isLoading, error };
|
|
157
102
|
}
|
|
158
103
|
exports.default = useOAuthSignIn;
|
|
159
104
|
//# sourceMappingURL=useOAuthSignIn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOAuthSignIn.js","sourceRoot":"","sources":["../../../src/hooks/useOAuthSignIn.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useOAuthSignIn.js","sourceRoot":"","sources":["../../../src/hooks/useOAuthSignIn.ts"],"names":[],"mappings":";;AAAA,iCAA8C;AAC9C,wCAQuB;AAEvB,MAAM,QAAQ,GAAG,4BAA4B,CAAC;AAa9C;;;;;;;;;;;;;;GAcG;AACH,SAAS,cAAc;IACrB,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,iBAAU,GAAE,CAAC;IACnC,MAAM,QAAQ,GAAG,IAAA,yBAAkB,GAAE,CAAC;IACtC,MAAM,WAAW,GAAG,IAAA,yBAAkB,EAAC,wBAAiB,CAAC,CAAC;IAC1D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAClD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAgB,IAAI,CAAC,CAAC;IAExD,wDAAwD;IACxD,MAAM,cAAc,GAAG,IAAA,mBAAW,EAChC,KAAK,EAAE,QAA8B,EAAE,QAAgB,EAAE,iBAA0B,EAAE,EAAE;QACrF,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,QAAQ,CAAC,yBAAyB,CAAC,CAAC;YACpC,OAAO;QACT,CAAC;QAED,IAAI,QAAQ,KAAK,MAAM,IAAI,CAAC,WAAW,EA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EAAiE;YACjE,+DAA+D;YAC/D,QAAQ,CAAC,IAAA,gBAAS,EAAC,EAAE,WAAW,EAAE,mBAAmB,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;YACxE,QAAQ,CAAC,IAAA,qBAAc,EAAC,IAAI,CAAC,CAAC,CAAC;YAE/B,gEAAgE;YAChE,mEAAmE;YACnE,kEAAkE;YAClE,IAAI,SAAS,EAAE,CAAC;gBACd,QAAQ,CAAC,IAAA,iCAA0B,EAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;YACtD,CAAC;YAED,0CAA0C;YAC1C,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;IAE1B,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACrF,CAAC;AAED,kBAAe,cAAc,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -18,17 +18,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.ReplykeProvider = exports.useOAuthSignIn = void 0;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
22
|
+
const core_1 = require("@replyke/core");
|
|
23
|
+
const AccountManager_1 = __importDefault(require("./AccountManager"));
|
|
24
24
|
// Re-export all exports from @replyke/core
|
|
25
25
|
__exportStar(require("@replyke/core"), exports);
|
|
26
26
|
// Web-only OAuth hook (uses window.location for redirect-based flow)
|
|
27
27
|
var useOAuthSignIn_1 = require("./hooks/useOAuthSignIn");
|
|
28
28
|
Object.defineProperty(exports, "useOAuthSignIn", { enumerable: true, get: function () { return __importDefault(useOAuthSignIn_1).default; } });
|
|
29
29
|
// Override ReplykeProvider to inject AccountManager
|
|
30
|
-
|
|
31
|
-
var projectId = _a.projectId, signedToken = _a.signedToken, children = _a.children;
|
|
30
|
+
const ReplykeProvider = ({ projectId, signedToken, children }) => {
|
|
32
31
|
return ((0, jsx_runtime_1.jsx)(core_1.ReplykeProvider, { projectId: projectId, signedToken: signedToken, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(AccountManager_1.default, {}), children] }) }));
|
|
33
32
|
};
|
|
34
33
|
exports.ReplykeProvider = ReplykeProvider;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,wCAAuE;AACvE,sEAA8C;AAE9C,2CAA2C;AAC3C,gDAA8B;AAE9B,qEAAqE;AACrE,yDAA8F;AAArF,iIAAA,OAAO,OAAkB;AAElC,oDAAoD;AAC7C,MAAM,eAAe,GAIvB,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC5C,OAAO,CACL,uBAAC,sBAAmB,IAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,YACjE,6DACE,uBAAC,wBAAc,KAAG,EACjB,QAAQ,IACR,GACiB,CACvB,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,eAAe,mBAa1B"}
|
|
@@ -1,81 +1,29 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
1
|
import { useAccountSync, useProject, handleError } from "@replyke/core";
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
getAccountMap
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
catch (_b) {
|
|
49
|
-
return [2 /*return*/, null];
|
|
50
|
-
}
|
|
51
|
-
return [2 /*return*/];
|
|
52
|
-
});
|
|
53
|
-
});
|
|
2
|
+
const STORAGE_KEY_PREFIX = "replyke-accounts:";
|
|
3
|
+
const webAccountStorage = {
|
|
4
|
+
async getAccountMap(projectId) {
|
|
5
|
+
try {
|
|
6
|
+
const raw = localStorage.getItem(`${STORAGE_KEY_PREFIX}${projectId}`);
|
|
7
|
+
return raw ? JSON.parse(raw) : null;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
54
12
|
},
|
|
55
|
-
setAccountMap
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
handleError(error, "Failed to write account map to localStorage");
|
|
63
|
-
}
|
|
64
|
-
return [2 /*return*/];
|
|
65
|
-
});
|
|
66
|
-
});
|
|
13
|
+
async setAccountMap(projectId, map) {
|
|
14
|
+
try {
|
|
15
|
+
localStorage.setItem(`${STORAGE_KEY_PREFIX}${projectId}`, JSON.stringify(map));
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
handleError(error, "Failed to write account map to localStorage");
|
|
19
|
+
}
|
|
67
20
|
},
|
|
68
|
-
deleteAccountMap
|
|
69
|
-
|
|
70
|
-
return __generator(this, function (_a) {
|
|
71
|
-
localStorage.removeItem("".concat(STORAGE_KEY_PREFIX).concat(projectId));
|
|
72
|
-
return [2 /*return*/];
|
|
73
|
-
});
|
|
74
|
-
});
|
|
21
|
+
async deleteAccountMap(projectId) {
|
|
22
|
+
localStorage.removeItem(`${STORAGE_KEY_PREFIX}${projectId}`);
|
|
75
23
|
},
|
|
76
24
|
};
|
|
77
25
|
function AccountManager() {
|
|
78
|
-
|
|
26
|
+
const { projectId } = useProject();
|
|
79
27
|
useAccountSync(webAccountStorage, projectId);
|
|
80
28
|
return null;
|
|
81
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountManager.js","sourceRoot":"","sources":["../../src/AccountManager.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AccountManager.js","sourceRoot":"","sources":["../../src/AccountManager.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGxE,MAAM,kBAAkB,GAAG,mBAAmB,CAAC;AAE/C,MAAM,iBAAiB,GAAoB;IACzC,KAAK,CAAC,aAAa,CAAC,SAAiB;QACnC,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,kBAAkB,GAAG,SAAS,EAAE,CAAC,CAAC;YACtE,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACtC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,SAAiB,EAAE,GAAe;QACpD,IAAI,CAAC;YACH,YAAY,CAAC,OAAO,CAClB,GAAG,kBAAkB,GAAG,SAAS,EAAE,EACnC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CACpB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,WAAW,CAAC,KAAK,EAAE,6CAA6C,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,SAAiB;QACtC,YAAY,CAAC,UAAU,CAAC,GAAG,kBAAkB,GAAG,SAAS,EAAE,CAAC,CAAC;IAC/D,CAAC;CACF,CAAC;AAEF,SAAS,cAAc;IACrB,MAAM,EAAE,SAAS,EAAE,GAAG,UAAU,EAAE,CAAC;IACnC,cAAc,CAAC,iBAAiB,EAAE,SAAU,CAAC,CAAC;IAC9C,OAAO,IAAI,CAAC;AACd,CAAC;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -1,42 +1,6 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
1
|
import { useCallback, useState } from "react";
|
|
38
2
|
import { useProject, useReplykeDispatch, useReplykeSelector, setTokens, setInitialized, selectAccessToken, requestNewAccessTokenThunk, } from "@replyke/core";
|
|
39
|
-
|
|
3
|
+
const BASE_URL = "https://api.replyke.com/v7";
|
|
40
4
|
/**
|
|
41
5
|
* Web-only hook for OAuth sign-in and identity linking.
|
|
42
6
|
* Uses window.location for redirect-based OAuth flow.
|
|
@@ -53,81 +17,62 @@ var BASE_URL = "https://api.replyke.com/v7";
|
|
|
53
17
|
* useEffect(() => { handleOAuthCallback(); }, []);
|
|
54
18
|
*/
|
|
55
19
|
function useOAuthSignIn() {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
var _b = useState(null), error = _b[0], setError = _b[1];
|
|
20
|
+
const { projectId } = useProject();
|
|
21
|
+
const dispatch = useReplykeDispatch();
|
|
22
|
+
const accessToken = useReplykeSelector(selectAccessToken);
|
|
23
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
24
|
+
const [error, setError] = useState(null);
|
|
62
25
|
// Shared helper for both /authorize and /link endpoints
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
headers = {
|
|
83
|
-
"Content-Type": "application/json",
|
|
84
|
-
};
|
|
85
|
-
if (endpoint === "link") {
|
|
86
|
-
headers["Authorization"] = "Bearer ".concat(accessToken);
|
|
87
|
-
}
|
|
88
|
-
return [4 /*yield*/, fetch("".concat(BASE_URL, "/").concat(projectId, "/oauth/").concat(endpoint), {
|
|
89
|
-
method: "POST",
|
|
90
|
-
headers: headers,
|
|
91
|
-
body: JSON.stringify({ provider: provider, redirectAfterAuth: redirect }),
|
|
92
|
-
})];
|
|
93
|
-
case 2:
|
|
94
|
-
response = _a.sent();
|
|
95
|
-
if (!!response.ok) return [3 /*break*/, 4];
|
|
96
|
-
return [4 /*yield*/, response.json()];
|
|
97
|
-
case 3:
|
|
98
|
-
data_1 = _a.sent();
|
|
99
|
-
throw new Error(data_1.error || "Failed to initiate OAuth");
|
|
100
|
-
case 4: return [4 /*yield*/, response.json()];
|
|
101
|
-
case 5:
|
|
102
|
-
data = _a.sent();
|
|
103
|
-
// Redirect browser to provider's authorization page.
|
|
104
|
-
// isLoading intentionally stays true since we're navigating away.
|
|
105
|
-
window.location.href = data.authorizationUrl;
|
|
106
|
-
return [3 /*break*/, 7];
|
|
107
|
-
case 6:
|
|
108
|
-
err_1 = _a.sent();
|
|
109
|
-
setError(err_1.message);
|
|
110
|
-
setIsLoading(false);
|
|
111
|
-
return [3 /*break*/, 7];
|
|
112
|
-
case 7: return [2 /*return*/];
|
|
26
|
+
const startOAuthFlow = useCallback(async (endpoint, provider, redirectAfterAuth) => {
|
|
27
|
+
if (!projectId) {
|
|
28
|
+
setError("No projectId available.");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (endpoint === "link" && !accessToken) {
|
|
32
|
+
setError("Must be authenticated to link an OAuth provider.");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
setIsLoading(true);
|
|
36
|
+
setError(null);
|
|
37
|
+
try {
|
|
38
|
+
const redirect = redirectAfterAuth || window.location.href;
|
|
39
|
+
// /authorize is unauthenticated, /link requires the access token
|
|
40
|
+
const headers = {
|
|
41
|
+
"Content-Type": "application/json",
|
|
42
|
+
};
|
|
43
|
+
if (endpoint === "link") {
|
|
44
|
+
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
113
45
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
46
|
+
const response = await fetch(`${BASE_URL}/${projectId}/oauth/${endpoint}`, {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers,
|
|
49
|
+
body: JSON.stringify({ provider, redirectAfterAuth: redirect }),
|
|
50
|
+
});
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
const data = await response.json();
|
|
53
|
+
throw new Error(data.error || "Failed to initiate OAuth");
|
|
54
|
+
}
|
|
55
|
+
const data = await response.json();
|
|
56
|
+
// Redirect browser to provider's authorization page.
|
|
57
|
+
// isLoading intentionally stays true since we're navigating away.
|
|
58
|
+
window.location.href = data.authorizationUrl;
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
setError(err.message);
|
|
62
|
+
setIsLoading(false);
|
|
63
|
+
}
|
|
64
|
+
}, [projectId, accessToken]);
|
|
65
|
+
const initiateOAuth = useCallback((provider, redirectAfterAuth) => startOAuthFlow("authorize", provider, redirectAfterAuth), [startOAuthFlow]);
|
|
66
|
+
const linkOAuthProvider = useCallback((provider, redirectAfterAuth) => startOAuthFlow("link", provider, redirectAfterAuth), [startOAuthFlow]);
|
|
67
|
+
const handleOAuthCallback = useCallback(() => {
|
|
123
68
|
// Tokens arrive in the URL fragment (#accessToken=...&refreshToken=...)
|
|
124
69
|
// Errors arrive in query params (?error=...&error_description=...)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
70
|
+
const hash = window.location.hash.substring(1); // Remove leading #
|
|
71
|
+
const fragmentParams = new URLSearchParams(hash);
|
|
72
|
+
const queryParams = new URLSearchParams(window.location.search);
|
|
73
|
+
const fragmentAccessToken = fragmentParams.get("accessToken");
|
|
74
|
+
const refreshToken = fragmentParams.get("refreshToken");
|
|
75
|
+
const oauthError = queryParams.get("error");
|
|
131
76
|
if (oauthError) {
|
|
132
77
|
setError(queryParams.get("error_description") || oauthError);
|
|
133
78
|
// Clean URL
|
|
@@ -137,13 +82,13 @@ function useOAuthSignIn() {
|
|
|
137
82
|
if (fragmentAccessToken && refreshToken) {
|
|
138
83
|
// Store tokens in Redux. The AccountManager (via useAccountSync)
|
|
139
84
|
// will detect the new tokens and persist them to localStorage.
|
|
140
|
-
dispatch(setTokens({ accessToken: fragmentAccessToken, refreshToken
|
|
85
|
+
dispatch(setTokens({ accessToken: fragmentAccessToken, refreshToken }));
|
|
141
86
|
dispatch(setInitialized(true));
|
|
142
87
|
// Fetch user profile so useAccountSync can persist the account.
|
|
143
88
|
// The thunk reads the just-set refresh token from Redux, calls the
|
|
144
89
|
// server, and dispatches setUser + setUserInUserSlice on success.
|
|
145
90
|
if (projectId) {
|
|
146
|
-
dispatch(requestNewAccessTokenThunk({ projectId
|
|
91
|
+
dispatch(requestNewAccessTokenThunk({ projectId }));
|
|
147
92
|
}
|
|
148
93
|
// Clean URL (remove fragment with tokens)
|
|
149
94
|
window.history.replaceState({}, "", window.location.pathname);
|
|
@@ -151,7 +96,7 @@ function useOAuthSignIn() {
|
|
|
151
96
|
}
|
|
152
97
|
return false;
|
|
153
98
|
}, [dispatch, projectId]);
|
|
154
|
-
return { initiateOAuth
|
|
99
|
+
return { initiateOAuth, linkOAuthProvider, handleOAuthCallback, isLoading, error };
|
|
155
100
|
}
|
|
156
101
|
export default useOAuthSignIn;
|
|
157
102
|
//# sourceMappingURL=useOAuthSignIn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOAuthSignIn.js","sourceRoot":"","sources":["../../../src/hooks/useOAuthSignIn.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useOAuthSignIn.js","sourceRoot":"","sources":["../../../src/hooks/useOAuthSignIn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,kBAAkB,EAClB,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,eAAe,CAAC;AAEvB,MAAM,QAAQ,GAAG,4BAA4B,CAAC;AAa9C;;;;;;;;;;;;;;GAcG;AACH,SAAS,cAAc;IACrB,MAAM,EAAE,SAAS,EAAE,GAAG,UAAU,EAAE,CAAC;IACnC,MAAM,QAAQ,GAAG,kB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core";
|
|
|
6
6
|
// Web-only OAuth hook (uses window.location for redirect-based flow)
|
|
7
7
|
export { default as useOAuthSignIn } from "./hooks/useOAuthSignIn";
|
|
8
8
|
// Override ReplykeProvider to inject AccountManager
|
|
9
|
-
export
|
|
10
|
-
var projectId = _a.projectId, signedToken = _a.signedToken, children = _a.children;
|
|
9
|
+
export const ReplykeProvider = ({ projectId, signedToken, children }) => {
|
|
11
10
|
return (_jsx(CoreReplykeProvider, { projectId: projectId, signedToken: signedToken, children: _jsxs(_Fragment, { children: [_jsx(AccountManager, {}), children] }) }));
|
|
12
11
|
};
|
|
13
12
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,2CAA2C;AAC3C,cAAc,eAAe,CAAC;AAE9B,qEAAqE;AACrE,OAAO,EAAE,OAAO,IAAI,cAAc,EAA6B,MAAM,wBAAwB,CAAC;AAE9F,oDAAoD;AACpD,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,2CAA2C;AAC3C,cAAc,eAAe,CAAC;AAE9B,qEAAqE;AACrE,OAAO,EAAE,OAAO,IAAI,cAAc,EAA6B,MAAM,wBAAwB,CAAC;AAE9F,oDAAoD;AACpD,MAAM,CAAC,MAAM,eAAe,GAIvB,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC5C,OAAO,CACL,KAAC,mBAAmB,IAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,YACjE,8BACE,KAAC,cAAc,KAAG,EACjB,QAAQ,IACR,GACiB,CACvB,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@replyke/react-js",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.107",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Replyke, maintained by Yanay Tsabary",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://docs.replyke.com",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@replyke/core": "7.0.0-beta.
|
|
41
|
+
"@replyke/core": "7.0.0-beta.107"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@reduxjs/toolkit": "^2.0.0",
|