1.0.2 • Published 4 years ago

storyblok-app-auth-express v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Storyblok App Auth (Express)

npm (scoped with tag) npm js-standard-style

A straight forward way to use Express with Storyblok Apps

Requirements

You can create a custom Storyblok app only if you are part of the partner program.

Installation

npm install --save storyblok-app-auth-express

Usage Example

Just require the package and use it as a middleware in your Express App.

const express = require('express');
const storyblokAuth = require('storyblok-app-auth-express');
const app = express();

app.use(storyblokAuth({
  client_id: '',
  client_secret: '',
  redirect_uri: 'https://yourapp.com/callback'
}));

app.get('/', async (req, res) => {
  try {
    const response = await req.storyblok.get('oauth/user_info');
    res.send(`Hello ${response.data.user.friendly_name}!`);
  } catch (e) {
    res.json({ error: e.message });
  }
});

app.listen(3000);

Using the Storyblok Client Object

As long as you provide the space ID in the query parameters or as segment item (?space_id or /:space_id) you will be able to use the req.storyblok object (like in the example above) which is just a wrapper for the storyblok-js-client object (https://github.com/storyblok/storyblok-js-client).

License

MIT License