Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ACKEE_ANONYMOUS Environmental Variable For Allowing Users To View The Ackee UI Without Logging In #278

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"ACKEE_TRACKER": {
"description": "Specifies a custom name for the tracking script (Default: tracker.js)",
"required": false
},
"ACKEE_ANONYMOUS": {
"description": "When set to true, allows users to view the Ackee UI without a username and password",
"required": false
}
}
}
}
188 changes: 94 additions & 94 deletions dist/index.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ ACKEE_USERNAME=username
ACKEE_PASSWORD=password
```

## Anonymous Mode

When set to `true`, allows users to access the Ackee UI without a username or password. Can be useful for when Ackee is behind a reverse proxy and the reverse proxy is handling authentication.

```
ACKEE_ANONYMOUS=true
```

## TTL

Specifies how long a generated token is valid. Defaults to `3600000` (1 day).
Expand Down
3 changes: 2 additions & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
ACKEE_MONGODB = "ACKEE_MONGODB"
ACKEE_USERNAME = "ACKEE_USERNAME"
ACKEE_PASSWORD = "ACKEE_PASSWORD"
ACKEE_ALLOW_ORIGIN = "ACKEE_ALLOW_ORIGIN"
ACKEE_ALLOW_ORIGIN = "ACKEE_ALLOW_ORIGIN"
ACKEE_ANONYMOUS = "ACKEE_ANONYMOUS"
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ connect(config.dbUrl).then(() => {
if (config.isDemoMode === true) {
signale.info('Demo mode enabled')
}

if (config.isAnonymousMode === true) {
signale.info('Anonymous mode enabled')
}
})
.catch((error) => {
signale.fatal(error)
Expand Down
13 changes: 8 additions & 5 deletions src/resolvers/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ const response = (entry) => ({
module.exports = {
Mutation: {
createToken: async (parent, { input }, { setCookies }) => {
const { username, password } = input
// If anonymous mode then skip checking for a username and password and just make the token
if (!config.isAnonymousMode) {
const { username, password } = input

if (config.username == null) throw new KnownError('Ackee username missing in environment')
if (config.password == null) throw new KnownError('Ackee username missing in environment')
if (config.username == null) throw new KnownError('Ackee username missing in environment')
if (config.password == null) throw new KnownError('Ackee username missing in environment')

if (username !== config.username) throw new KnownError('Username or password incorrect')
if (password !== config.password) throw new KnownError('Username or password incorrect')
if (username !== config.username) throw new KnownError('Username or password incorrect')
if (password !== config.password) throw new KnownError('Username or password incorrect')
}

const entry = await tokens.add()

Expand Down
1 change: 1 addition & 0 deletions src/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const signale = require('../utils/signale')
const index = () => {
return layout('<div id="main"></div>', 'favicon.ico', [ 'index.css' ], [ 'index.js' ], {
isDemoMode: config.isDemoMode,
isAnonymousMode: config.isAnonymousMode,
customTracker,
})
}
Expand Down
17 changes: 17 additions & 0 deletions src/ui/scripts/components/overlays/OverlayLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ const OverlayLogin = (props) => {
props.setToken(data.createToken.payload.id)
}

// If in anonymous mode go ahead and generate the token and then close this modal
const createAnonymousToken = async () => {
const { data } = await createToken.mutate({
variables: {
input: {
username: 'anonymous',
password: 'anonymous',
},
},
})
props.setToken(data.createToken.payload.id)
}

if (window.env.isAnonymousMode) {
createAnonymousToken()
}

return (
h('form', { className: 'card card--overlay', onSubmit },
h('div', { className: 'card__inner align-center' },
Expand Down
22 changes: 15 additions & 7 deletions src/ui/scripts/components/routes/RouteSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,24 @@ const RouteSettings = (props) => {
const eventsItems = createItems(events.value, showEventEditModal, showEventAddModal, 'New event')
const permanentTokensItems = createItems(permanentTokens.value, showPermanentTokenEditModal, showPermanentTokenAddModal, 'New permanent token')

const accountCard = window.env.isAnonymousMode ?
h(CardSetting, {
headline: 'Account',
},
h(LinkItem, { type: 'p', disabled: true, text: version }, 'Version'),
) :
h(CardSetting, {
headline: 'Account',
},
h(LinkItem, { type: 'p', disabled: true, text: version }, 'Version'),
h(Line),
h(LinkItem, { type: 'button', onClick: onSignOut }, 'Sign Out'),
)

return (
h(Fragment, {},

h(CardSetting, {
headline: 'Account',
},
h(LinkItem, { type: 'p', disabled: true, text: version }, 'Version'),
h(Line),
h(LinkItem, { type: 'button', onClick: onSignOut }, 'Sign Out'),
),
accountCard,

h(CardSetting, {
headline: 'Domains',
Expand Down
1 change: 1 addition & 0 deletions src/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = new Proxy({}, {
isDemoMode: process.env.ACKEE_DEMO === 'true',
isDevelopmentMode: process.env.NODE_ENV === 'development',
isPreBuildMode: process.env.BUILD_ENV === 'pre',
isAnonymousMode: process.env.ACKEE_ANONYMOUS,
}

return data[prop]
Expand Down