Tutorial: Build a Basic CRUD App with Node.js

mandriga

Hi, I am getting the error - unauthenticated page when I click login… then nothing when I click the login link in the error page. Please advise. Thank you.

Matt Raible

Can you please compare your code with the example app on GitHub. You can use SmartSynchronize to compare directories. I recommend ignoring (or deleting) node_modules beforehand.

Abhinav Priyadarshi

Hi,
I get this as an error - throw new ConfigurationValidationError(‘Your appBaseUrl is missing.’);
What to do ???

Matt Raible

We released a new version of oidc-middleware (Express) package last month: https://github.com/okta/okt…

This is a new major version which does include breaking changes, including this new appBaseUrl parameter. If you use the version specified in this post, it should work.

Randall Degges

Will consider this for future articles! We’re still building out tons of stuff. Please hit me up with any other suggestions of things you’d like to see in the future! I’m randall.degges@okta.com

Randall Degges

Hi there! It sounds like you didn’t install all of the required dependencies. Maybe when you ran the NPM commands one of them was missed, or a download failed. You can try it again and things should work great.

Randall Degges

This looks like you didn’t install all of the required dependencies. Maybe when you ran the NPM commands one of them was missed, or a download failed. You can try it again and things should work great.

Randall Degges

Hmm… I just tested the tutorial out fresh, and it is working great with what is there currently.

I’m not sure what is causing this issue – it may be that your route code for listing the home page wasn’t properly copied (or maybe you removed some of the default code and replaced it?) – that index route needs to generate an array of posts, even if it is empty. Otherwise you would see an error like this one.

TT

Hi,
I am getting a 404 error if I follow the tutorial OR download the example code from github.
If I were to change the application redirect uri on the site to /authorization-code/callback - i dont get a 404 but there is no login prompt or otherwise any message or activity. The control stays on Home screen.

Any pointers will be appreciated.

Thanks
Tapan

Peter Filias

I am just going through this tutorial and am getting errors when trying to install sqlite (npm install sqlite3@4.0.1).

Here is the output:

> sqlite3@4.0.1 install /Users/pfilias/blog/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Tried to download(403): https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.0.1/node-v72-darwin-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for sqlite3@4.0.1 and node@12.18.3 (node-v72 ABI, unknown) (falling back to source compile with node-gyp)
No receipt for ‘com.apple.pkg.CLTools_Executables’ found at ‘/’.

No receipt for ‘com.apple.pkg.DeveloperToolsCLILeo’ found at ‘/’.

No receipt for ‘com.apple.pkg.DeveloperToolsCLI’ found at ‘/’.

gyp: No Xcode or CLT version detected!
gyp ERR! configure error
gyp ERR! stack Error: gyp failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack at ChildProcess.emit (events.js:315:20)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Darwin 19.6.0
gyp ERR! command “/usr/local/bin/node” “/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” “configure” “–fallback-to-build” “–module=/Users/pfilias/blog/node_modules/sqlite3/lib/binding/node-v72-darwin-x64/node_sqlite3.node” “–module_name=node_sqlite3” “–module_path=/Users/pfilias/blog/node_modules/sqlite3/lib/binding/node-v72-darwin-x64” “–napi_version=6” "–node_abi_napi=napi"
gyp ERR! cwd /Users/pfilias/blog/node_modules/sqlite3
gyp ERR! node -v v12.18.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute ‘/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/pfilias/blog/node_modules/sqlite3/lib/binding/node-v72-darwin-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/Users/pfilias/blog/node_modules/sqlite3/lib/binding/node-v72-darwin-x64 --napi_version=6 --node_abi_napi=napi’ (1)
node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/Users/pfilias/blog/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:315:20)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:1021:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
node-pre-gyp ERR! System Darwin 19.6.0
node-pre-gyp ERR! command “/usr/local/bin/node” “/Users/pfilias/blog/node_modules/.bin/node-pre-gyp” “install” "–fallback-to-build"
node-pre-gyp ERR! cwd /Users/pfilias/blog/node_modules/sqlite3
node-pre-gyp ERR! node -v v12.18.3
node-pre-gyp ERR! node-pre-gyp -v v0.10.3
node-pre-gyp ERR! not ok
Failed to execute ‘/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/pfilias/blog/node_modules/sqlite3/lib/binding/node-v72-darwin-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/Users/pfilias/blog/node_modules/sqlite3/lib/binding/node-v72-darwin-x64 --napi_version=6 --node_abi_napi=napi’ (1)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sqlite3@4.0.1 install: node-pre-gyp install --fallback-to-build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sqlite3@4.0.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/pfilias/.npm/_logs/2020-09-02T14_10_56_186Z-debug.log

David Neal

Hi Peter,

You may need to install or re-install your Xcode command-line tools. I recently had to remove and re-install the Xcode command-line tools on my Mac after an update. Also, you can try installing a later version of sqlite3 using npm install sqlite3@4. I believe the latest minor version 4.x of sqlite will still be compatible with the code in this post.

I hope this helps!
David

Peter Filias

I had not installed Xcode command-line tools. I just did, still got an error. I will try a newer version of sqlite3 like you mentioned. By the way, I have Xcode 11.7 installed but the only Xcode command-line tools that was close was 11.5 - the newer versions are version 12 beta. I am unable to post my error output as it’s way too long.

> sqlite3@4.0.1 install /Users/pfilias/blog/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build

Peter Filias

I went through the entire tutorial and fired it up with npm start. I got some warnings.

sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at Manual | Sequelize node_modules/sequelize/lib/sequelize.js:242:13
(node:7013) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
Executing (default): CREATE TABLE IF NOT EXISTS posts (id INTEGER PRIMARY KEY AUTOINCREMENT, title VARCHAR(255), body TEXT, authorId VARCHAR(255), slug VARCHAR(255), createdAt DATETIME NOT NULL, updatedAt DATETIME NOT NULL);
(node:7013) UnhandledPromiseRejectionWarning: RequestError: connect ECONNREFUSED 127.0.0.1:443
at ClientRequest.<anonymous> (/Users/pfilias/blog/node_modules/got/index.js:182:22)
at Object.onceWrapper (events.js:422:26)
at ClientRequest.emit (events.js:327:22)
at TLSSocket.socketErrorListener (_http_client.js:426:9)
at TLSSocket.emit (events.js:315:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:7013) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see Command-line options | Node.js v17.0.1 Documentation). (rejection id: 1)
(node:7013) [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.
Executing (default): PRAGMA INDEX_LIST(posts)

David Neal

Probably the best thing to do at this point is to clone this post’s repository and compare your code. You can also run npm install to install all the dependencies, plug in your client ID, secret, token, etc. and see if the repository’s code works for you.

Peter Filias

I actually did that, as the repository is slightly different from the tutorial posted on Okta’s site. That said, I did that, and still get a 400 Bad Request error when trying to login. I’m stumped, but not losing much sleep on it, either. I was just hoping to play and learn a little.

Matt Raible

A 400 error is typically caused by two things: 1) an invalid redirect URI or 2) an invalid client ID. If it’s an invalid redirect URI, the 400 error should state that. You can see the redirect URI it’s trying to go to if you look at the parameters in your address bar.

Peter Filias

It is an invalid redirect URI. I set that according to the documentation. Which was this: http://localhost:3000/users/callback.

Matt Raible

If you compare what’s in the URL (when you see this message) and what your Okta app has, you’ll see they don’t match. If you change your Okta app to match what you’re sending, everything will work.

Ahmed Suliman

Hello ! I have a small bug when I start “npm start” it appears I have an issue somewhere. https://uploads.disquscdn.c…

Hi I am getting an error “Only absolute URLs are supported” when trying to Login to the CRUD App - it may be something simple but am unable to fix right now …

// app.js extract follows
const oidc = new ExpressOIDC({
appBaseUrl: “http://localhost:3000”,
issuer: “https://dev-24200011.okta.com/oauth2/default”,
// …

npm start

blog@0.0.0 start
node ./bin/www

Executing (default): SELECT name FROM sqlite_master WHERE type=‘table’ AND name=‘posts’;
Executing (default): PRAGMA INDEX_LIST(posts)
GET /users/login 302 20.704 ms - 0
GET /authorization-code/callback?code=-uNiGCvz-9mmeFSyOU2g9sU-0ywpiirwKt5PawmKiCA&state=c5R8UCkKt0cBhcu-aaqbrqOUqS0wE0I7QbyIbSiUUWw 302 2772.040 ms - 64
/Users/tonyodonnell/Library/Mobile Documents/com~apple~CloudDocs/Dev/node-okta/okta-express-basic-crud-app-example/node_modules/node-fetch/lib/index.js:1327
throw new TypeError(‘Only absolute URLs are supported’);
^

TypeError: Only absolute URLs are supported
at getNodeRequestOptions (/Users/tonyodonnell/Library/Mobile Documents/com~apple~CloudDocs/Dev/node-okta/okta-express-basic-crud-app-example/node_modules/node-fetch/lib/index.js:1327:9)
at /Users/tonyodonnell/Library/Mobile Documents/com~apple~CloudDocs/Dev/node-okta/okta-express-basic-crud-app-example/node_modules/node-fetch/lib/index.js:1440:19
at new Promise ()
at fetch (/Users/tonyodonnell/Library/Mobile Documents/com~apple~CloudDocs/Dev/node-okta/okta-express-basic-crud-app-example/node_modules/node-fetch/lib/index.js:1437:9)
at module.exports (/Users/tonyodonnell/Library/Mobile Documents/com~apple~CloudDocs/Dev/node-okta/okta-express-basic-crud-app-example/node_modules/isomorphic-fetch/fetch-npm-node.js:8:19)
at DefaultRequestExecutor.fetch (/Users/tonyodonnell/Library/Mobile Documents/com~apple~CloudDocs/Dev/node-okta/okta-express-basic-crud-app-example/node_modules/@okta/okta-sdk-nodejs/src/request-executor.js:19:12)
at DefaultRequestExecutor.fetch (/Users/tonyodonnell/Library/Mobile Documents/com~apple~CloudDocs/Dev/node-okta/okta-express-basic-crud-app-example/node_modules/@okta/okta-sdk-nodejs/src/default-request-executor.js:63:18)
at /Users/tonyodonnell/Library/Mobile Documents/com~apple~CloudDocs/Dev/node-okta/okta-express-basic-crud-app-example/node_modules/@okta/okta-sdk-nodejs/src/http.js:81:42