![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
feathers-authentication
Advanced tools
Add Authentication to your FeathersJS app.
feathers-authentication
adds shared PassportJS authentication for Feathers HTTP REST and websockets services using JSON Web Tokens.
If you are using the default options, setting up JWT auth for your Feathers app is as simple as the below example. Note: You must set up the body-parser
module before setting up feathers-authentication
.
var feathers = require('feathers');
var hooks = require('feathers-hooks');
var bodyParser = require('body-parser');
var feathersAuth = require('feathers-authentication').default;
var authHooks = require('feathers-authentication').hooks;
var mongooseService = require('feathers-mongoose');
var app = feathers()
.configure(feathers.rest())
.configure(feathers.socketio())
.configure(hooks())
.use(bodyParser.urlencoded({ extended: true }))
// Configure feathers-authentication
.configure(feathersAuth({
secret: 'feathers-rocks'
}))
.use('/api/users', new mongooseService('user', {
schema: {
email: {type: String, required: true, unique: true },
password: {type: String, required: true },
admin: {type: Boolean, default: false }
},
before:{
create: [authHooks.hashPassword('password')]
}
}))
Authenticated REST requests must have an Authorization
header in the format 'Bearer <token>'
, where the is the JWT token. For example:
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IklseWEgRmFkZWV2IiwiYWRtaW4iOnRydWV9.YiG9JdVVm6Pvpqj8jDT5bMxsm0gwoQTOaZOLI-QfSNc
In order to authenticate a Websocket connection, you must first obtain a token using an Ajax request to your loginEndpoint
. You then include that token in the request. The example below is for Socket.io, but the same query
key can be passed to Primus.
socket = io('', {
// Assuming you've already saved a token to localStorage.
query: 'token=' + localStorage.getItem('featherstoken'),
transports: ['websocket'], // optional, see below
forceNew:true, // optional, see below
});
In the above example, the transports
key is only needed if you for some reason need to force the browser to only use websockets. The forceNew
key is only needed if you have previously connected an unauthenticated Websocket connection and you now want to start an authenticated request.
The following options are available:
'/api/users
./api/login
. You can also post a valid token here to receive a new one. You might use this when the current auth token is about to expire to stay logged in on the client.username
.password
.require('passport')
) - The passport moduleThe feathers-authentication
plugin automatically handles auth. Keep in mind that access control is not automatic, but is easy to set up with the included hooks. See the feathers-hooks plugin and the FeathersJS website for more information about hooks.
This is intended to be used on the user service on the create
method. It will automatically hash the data coming in on the password
field. You can specify another field by providing another string.
The following shows a commented example for an application using local authentication with a Feathers user service:
var feathers = require('feathers');
var passport = require('passport');
var hooks = require('feathers-hooks');
var memory = require('feathers-memory');
var bodyParser = require('body-parser');
var feathersAuth = require('feathers-authentication').default;
var authHooks = require('feathers-authentication').hooks;
// Initialize the application
var app = feathers()
.configure(feathers.rest())
.configure(feathers.socketio())
.configure(hooks())
// Needed for parsing bodies (login)
.use(bodyParser.urlencoded({ extended: true }))
// Configure feathers-authentication
.configure(feathersAuth({
secret: 'feathers-rocks'
}))
// Initialize a user service
.use('/api/users', memory())
// A simple Todos service that we can used for testing
.use('/todos', {
get: function(id, params, callback) {
callback(null, {
id: id,
text: 'You have to do ' + id + '!',
user: params.user
});
}
})
.use('/', feathers.static(__dirname));
var userService = app.service('/api/users');
// Add a hook to the user service that automatically replaces
// the password with a hash of the password before saving it.
userService.before({
create: authHooks.hashPassword('password')
});
// Create a user that we can use to log in
userService.create({
username: 'feathers',
password: 'secret'
}, {}, function(error, user) {
console.log('Created default user', user);
});
app.listen(4000);
Add a login.html
with an HTML form that allows to log our user in:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="/login" method="post">
<div>
<label>Username:</label>
<input type="text" name="username"/>
</div>
<div>
<label>Password:</label>
<input type="password" name="password"/>
</div>
<div>
<input type="submit" value="Log In"/>
</div>
</form>
</body>
</html>
0.0.5
Copyright (c) 2015
Licensed under the MIT license.
v0.0.7 (2016-01-07)
Closed issues:
.default
#13Merged pull requests:
FAQs
Add Authentication to your FeathersJS app.
The npm package feathers-authentication receives a total of 56 weekly downloads. As such, feathers-authentication popularity was classified as not popular.
We found that feathers-authentication demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.