Skip to content

Commit

Permalink
feat: store login events (#3185)
Browse files Browse the repository at this point in the history
## About the changes
https://linear.app/unleash/issue/2-705/store-sign-on-events

Adds a migration for a new `login_events` table. Also adds the new
`loginEventLog` feature flag.

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#2951

---------

Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai>
  • Loading branch information
nunogois and Christopher Kolstad committed Feb 23, 2023
1 parent 194c07e commit 25b7af3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/__snapshots__/create-config.test.ts.snap
Expand Up @@ -74,6 +74,7 @@ exports[`should create default config 1`] = `
"embedProxy": true,
"embedProxyFrontend": true,
"featuresExportImport": false,
"loginEventLog": false,
"maintenance": false,
"maintenanceMode": false,
"messageBanner": false,
Expand All @@ -96,6 +97,7 @@ exports[`should create default config 1`] = `
"embedProxy": true,
"embedProxyFrontend": true,
"featuresExportImport": false,
"loginEventLog": false,
"maintenance": false,
"maintenanceMode": false,
"messageBanner": false,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/types/experimental.ts
Expand Up @@ -67,6 +67,10 @@ const flags = {
false,
),
notifications: parseEnvVarBoolean(process.env.NOTIFICATIONS, false),
loginEventLog: parseEnvVarBoolean(
process.env.UNLEASH_LOGIN_EVENT_LOG,
false,
),
};

export const defaultExperimentalOptions: IExperimentalOptions = {
Expand Down
27 changes: 27 additions & 0 deletions src/migrations/20230222084211-add-login-events-table.js
@@ -0,0 +1,27 @@
exports.up = function (db, cb) {
db.runSql(
`
CREATE TABLE IF NOT EXISTS login_events (
id SERIAL PRIMARY KEY NOT NULL,
username TEXT NOT NULL,
auth_type TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
successful BOOLEAN NOT NULL,
ip INET,
failure_reason TEXT
);
CREATE INDEX IF NOT EXISTS login_events_ip_idx ON login_events(ip);
`,
cb,
);
};

exports.down = function (db, cb) {
db.runSql(
`
DROP INDEX IF EXISTS login_events_ip_idx;
DROP TABLE IF EXISTS login_events;
`,
cb,
);
};

0 comments on commit 25b7af3

Please sign in to comment.