How can I check user authentication in server with FeathersJS?

516 Views Asked by At

So currently, I am using feathers client auth and local strategy to authenticate my single-page app.

I've added different middleware routes and I want to check if user is authenticated and if not, redirect them to /.

This is one of my routes:

inside /src/middleware/index.php

app.get('/some-route', (req, res) => {
    res.render('some-view.ejs');
});

I've tried something like

const cookieParser = require('cookie-parser');
const auth = require('@feathersjs/authentication');

app.get('/some-route', cookieParser(), auth.express.authenticate('local'), (req, res) => {
    res.render('some-view.ejs');
});

But I only get missing credentials error, though in client side I am logged in and I can see the token in localStorage.

Am I missing something here? Thank you.

1

There are 1 best solutions below

0
On

I think you should try the following code instead...

app.get('/some-route', cookieParser(), authenticate("jwt"), (req, res) => {
    res.render('some-view.ejs');
});