Trinh_Nguyen | 2018-12-12 07:40:40 UTC | #1
Hi everybody,
I am using purecloud-platform-client-v2 sdk to login purecloud.
index.js const express = require('express'); const app = express();
const platformClient = require('purecloud-platform-client-v2'); const clientId = 'xxx'; const redirectUri = 'http://localhost:8080'; const environment = 'mypurecloud.jp'; const client = platformClient.ApiClient.instance; const state = 'state';
const hostname = 'localhost'; const port = 8080;
// CORSを許可する app.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", ""); res.header("Access-Control-Allow-Headers",""); res.header('Access-Control-Allow-Credentials', true); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); next(); });
app.get('/', (req, res) => { client.setEnvironment(environment); client.setPersistSettings(true, 'test_app'); client.loginImplicitGrant(clientId, redirectUri, { state: state }) .then((data) => { console.log(data); // Do authenticated things console.log("Log success"); }) .catch((err) => { // Handle failure response console.log(err); }); });
app.listen(port, hostname, () => { console.log(Server running at http://${hostname}:${port}/); });
After run 'node index.js' command and access url http://localhost:8080/, the following error is displayed. How to fix it? Thanks for help!
(node:32) UnhandledPromiseRejectionWarning: ReferenceError: window is not defined at testTokenAccess.then.catch (D:\Trinh\Working\purecloud\working\patrollamp\app\nodemodules\purecloud-platform-client-v2\dist\node\purecloud-platform-client-v2.js:278:6) at process.internalTickCallback (internal/process/nexttick.js:77:7) (node:32) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2) (node:32) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Trinh_Nguyen | 2018-12-12 08:53:36 UTC | #2
Sorry, I used code for web, not nodejs. Please close it.
system | 2019-01-12 08:53:39 UTC | #3
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 4170