Skip to content

Commit 467d3a8

Browse files
authored
🍕 Add preventAuth parameter (#40)
1 parent fe2025c commit 467d3a8

File tree

5 files changed

+45
-13
lines changed

5 files changed

+45
-13
lines changed

.circleci/config.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@ workflows:
102102
version: 2
103103
test:
104104
jobs:
105-
- test_node10:
106-
<<: *filter_all
107-
- test_node12:
108-
<<: *filter_all
109-
- test_node14:
110-
<<: *filter_all
111105
- deploy_package:
112106
<<: *filter_release
113107
context:

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ export LDAP_SEARCH_BASE=<LDAP_SEARCH_BASE>
8383
export LDAP_SEARCH_FILTER=<LDAP_SEARCH_FILTER>
8484
```
8585

86+
The following env variables are optional:
87+
88+
This flag, when true, will prevent users from either going into edit mode or making any edits to a page they had already opened in edit mode in their browsers. This environment variable is optional and you can set it up from your Clay instance and it'll be picked up here since it'll share the same env file!
89+
It will redirect users to the login page where they'll see a message saying that Clay is under maintenance.
90+
```bash
91+
export MAINTENANCE_MODE_ENABLED=true
92+
```
93+
8694
## License
8795

8896
MIT

constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ module.exports.AUTH_LEVELS = {
55
ADMIN: 'admin',
66
WRITE: 'write',
77
};
8+
module.exports.MAINTENANCE_MODE_ENABLED = Boolean(process.env.MAINTENANCE_MODE_ENABLED);

index.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const _isEmpty = require('lodash/isEmpty'),
1313
} = require('./utils'),
1414
createSessionStore = require('./services/session-store'),
1515
strategyService = require('./strategies'),
16-
{ AUTH_LEVELS } = require('./constants'),
16+
{ AUTH_LEVELS, MAINTENANCE_MODE_ENABLED } = require('./constants'),
1717
{ withAuthLevel } = require('./services/auth'),
1818
{ setDb } = require('./services/storage'),
1919
{ setBus } = require('./controllers/users');
@@ -39,6 +39,13 @@ function isProtectedRoute(req) {
3939
*/
4040
function isAuthenticated(site) {
4141
return function (req, res, next) {
42+
// This variable controls wether or not people can log in to Clay
43+
// and stops people from being able to make edits to pages.
44+
// If someone were to edit something on a tab that was already opened,
45+
// or attempted to go into edit mode, with this flag active,
46+
// they'd get redirected to a screen displaying a message that the CMS is under maintenance.
47+
if (MAINTENANCE_MODE_ENABLED) return res.redirect(`${getAuthUrl(site)}/login`);
48+
4249
if (req.isAuthenticated()) {
4350
next(); // already logged in
4451
} else if (req.get('Authorization')) {
@@ -98,13 +105,14 @@ function onLogin(site, providers) {
98105
// going to use varnish to automatically redirect them back to the ldap auth
99106
} else {
100107
res.send(template({
101-
path: getPathOrBase(site),
102-
flash: flash,
103108
currentProviders: currentProviders,
104-
user: req.user,
105-
logoutLink: `${authUrl}/logout`,
109+
flash: flash,
106110
localAuthPath: `${authUrl}/local`,
107-
useLocalAuth: providers.includes('local')
111+
logoutLink: `${authUrl}/logout`,
112+
path: getPathOrBase(site),
113+
maintenanceModeEnabled: MAINTENANCE_MODE_ENABLED,
114+
useLocalAuth: providers.includes('local'),
115+
user: req.user
108116
}));
109117
}
110118
};

views/login.handlebars

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
<meta charset="utf-8">
55
<title>Log In - Clay</title>
66
<style>
7+
@keyframes fadeIn {
8+
from {
9+
opacity: 0;
10+
}
11+
to {
12+
opacity: 1;
13+
}
14+
}
15+
animation: fadeIn 1s ease-in;
716
.flash-error,
817
.header,
918
.details,
@@ -53,6 +62,15 @@
5362
text-align: center;
5463
width: 100%;
5564
}
65+
.details.maintenance {
66+
animation: fadeIn 1s ease-in;
67+
background-color: #FFF3CD;
68+
border-radius: 5px;
69+
border: 2px solid #FFC107;
70+
color: #FF0000;
71+
font-size: 24px;
72+
padding: 20px;
73+
}
5674
5775
.header {
5876
margin-bottom: 0;
@@ -172,7 +190,10 @@
172190
{{else}}
173191
<h1 class="header">Welcome, {{ username }}</h1>
174192
{{/if}}
175-
<p class="details">You are currently logged in to Clay</p>
193+
<p class="details">You are currently logged in to Clay.</p>
194+
{{#if ../maintenanceModeEnabled}}
195+
<p class="details maintenance">Clay is undergoing some routine maintenance. It will be back online shortly.</p>
196+
{{/if}}
176197
{{else}}
177198
<h1 class="header">Log in to Clay</h1>
178199
{{#if currentProviders.length}}<p class="details">Please choose the provider attached to your account</p>{{/if}}

0 commit comments

Comments
 (0)