ReferenceError: window is not defined

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\patrol_lamp\app\node_modules\purecloud-platform-client-v2\dist\node\purecloud-platform-client-v2.js:278:6)
at process.internalTickCallback (internal/process/next_tick.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.

Sorry, I used code for web, not nodejs. Please close it.

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.