Skip to content

ChristopheCorbalan/storyblok-app-auth-express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

⚡ A straight forward way to use express with Storyblok Apps

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published