mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 18:32:41 +00:00
Add passwordless login for local installs
This commit is contained in:
@@ -36,6 +36,7 @@ const Homebrew = createClass({
|
||||
global.account = this.props.account;
|
||||
global.version = this.props.version;
|
||||
global.enable_v3 = this.props.enable_v3;
|
||||
global.config = this.props.config;
|
||||
},
|
||||
render : function (){
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const React = require('react');
|
||||
const createClass = require('create-react-class');
|
||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||
const jwt = require('jwt-simple');
|
||||
|
||||
const Account = createClass({
|
||||
displayName : 'AccountNavItem',
|
||||
@@ -25,7 +26,26 @@ const Account = createClass({
|
||||
};
|
||||
},
|
||||
|
||||
localLogin : function(){
|
||||
const username = prompt('Enter username:');
|
||||
if(!username) {return;};
|
||||
|
||||
const payload = {
|
||||
username : username,
|
||||
issued : new Date()
|
||||
};
|
||||
const expiry = new Date;
|
||||
expiry.setFullYear(expiry.getFullYear() + 1);
|
||||
const token = jwt.encode(payload, global.config.secret);
|
||||
|
||||
document.cookie = `nc_session=${token};expires=${expiry};path=/;samesite=lax;${window.domain ? `domain=${window.domain}` : ''}`;
|
||||
window.location.reload(true);
|
||||
},
|
||||
|
||||
render : function(){
|
||||
const localEnvironments = ['local', 'docker'];
|
||||
|
||||
// Logged in
|
||||
if(global.account){
|
||||
return <Nav.dropdown>
|
||||
<Nav.item
|
||||
@@ -53,6 +73,16 @@ const Account = createClass({
|
||||
</Nav.dropdown>;
|
||||
}
|
||||
|
||||
// Logged out
|
||||
// LOCAL ONLY
|
||||
if(localEnvironments.includes(global.config.environment)) {
|
||||
return <Nav.item color='teal' icon='fas fa-sign-in-alt' onClick={this.localLogin}>
|
||||
login
|
||||
</Nav.item>;
|
||||
};
|
||||
|
||||
// Logged out
|
||||
// Production site
|
||||
return <Nav.item href={`https://www.naturalcrit.com/login?redirect=${this.state.url}`} color='teal' icon='fas fa-sign-in-alt'>
|
||||
login
|
||||
</Nav.item>;
|
||||
|
||||
Reference in New Issue
Block a user