nickredmark / ooth

User identity/authentication/accounts management microservice for node.js
https://nmaro.github.io/ooth/
MIT License
605 stars 65 forks source link

TypeError: Ooth is not a constructor #67

Closed mlflabs closed 6 years ago

mlflabs commented 6 years ago

Here is an error, I presume it is from recent changes, since I just did an update to 2.30

TypeError: Ooth is not a constructor at start (/Users/mike/Projects/auth/index.js:39:22)

Here is my start script, I just copied your example:

const express = require('express')
const session = require('express-session')
const cors = require("cors");
const {promisify} = require('util')
const debug = require('debug')('index')

const Ooth = require('ooth')
const OothCouch = require('./auth-couchdb')
const oothLocal = require("ooth-local").default;
const oothUser = require("ooth-user").default;

const COUCH_HOST = 'http://localhost:5984'
const COUCH_AUTH_DB = 'auth'

const nano = require('nano')(COUCH_HOST);

const HOST = 'http://localhost'
const PORT = 3000

const SECRET = 'somesecret'
const SHARED_SECRET = 'somesharedsecret'
const OOTH_PATH = '/auth'
const LOGGING = 'debug';

const start = async () => {
    try {

        const db = nano.use(COUCH_AUTH_DB);

        const app = express()

        const oothCouch  = new OothCouch(db);

        const ooth = new Ooth({
            app,
            backend: oothCouch,
            sessionSecret: SECRET,
            path: OOTH_PATH 
          });

          oothLocal({
            ooth
          });
          oothUser({
            ooth
          });

          ooth.on("local", "register", ({ email, verificationToken, _id }) => {
            console.log(`Someone registered.`);
          });
          ooth.on(
            "local",
            "generate-verification-token",
            ({ email, verificationToken }) => {
              console.log(`Someone requested a verification email.`);
            }
          );
          ooth.on("local", "verify", ({ email }) => {
            console.log(`Someone verified their email`);
          });
          ooth.on("local", "forgot-password", ({ email, passwordResetToken }) => {
            console.log(`Someone forgot their password`);
          });
          ooth.on("local", "reset-password", ({ email }) => {
            console.log(`Someone reset their password`);
          });

          app.get("/", (req, res) => res.sendFile(`${__dirname}/index.html`));

          await new Promise((res, rej) =>
            app.listen(PORT, HOST, e => (e ? rej(e) : res()))
          );
          console.info(`Online at ${HOST}:${PORT}`);

        } catch (e) {
          console.error(e);
        }
}

start()
nickredmark commented 6 years ago

Yes there have been many breaking changes, sorry about that. Ooth 2 should be structured better now.

All classes aren't default exports anymore, so:

const { Ooth } = require('ooth');

Hey if your ooth-couchdb works I'd be happy if you contribute it :)

nickredmark commented 6 years ago

Just saw it was wrong in the documentation, sorry about that.

mlflabs commented 6 years ago

thx for the reply, its working now

btw, maybe i have missed it, but do you have any docs about the api, i want to use postman to do some api testing.

please mark as resolved

mike

nickredmark commented 6 years ago

@mlflabs the general api structure is

POST <ooth>/<stategy>/<method>

e.g. depending on your setup /auth/local/login or /auth/local/register

search for registerPrimaryAuth and registerMethod in this file to see what methods have been registered, it should be easy to see what parameters are needed.