Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit cb190f7

Browse files
committed
Rough demo of identity passthrough with Proxy
1 parent d85e6b1 commit cb190f7

File tree

7 files changed

+27
-7
lines changed

7 files changed

+27
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22

33
# Don't accidentally commit local credentials
44
.envrc
5+
tandem.toml

.tool-versions

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
nodejs 19.7.0
2-
postgres 15.1
3-
direnv 2.32.2
1+
nodejs 19.7.0
2+
postgres 15
3+
direnv 2.32.2

config/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"development": {
3-
"password": null,
3+
"user": "dan",
4+
"password": "12qwaszx",
45
"database": "sequelize-example",
56
"host": "127.0.0.1",
67
"dialect": "postgres",

models/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const env = process.env.NODE_ENV || 'development';
99
const config = require(__dirname + '/../config/config.json')[env];
1010
const db = {};
1111

12-
const setPort = (config) => !!process.env.STASH_DB_PORT ? { ...config, port: parseInt(process.env.STASH_DB_PORT, 10) } : config;
12+
const setPort = (config) => !!process.env.TANDEM_PORT ? { ...config, port: parseInt(process.env.TANDEM_PORT, 10) } : config;
1313
//const setPort = (config) => ({ ...config, port: parseInt(process.env.STASH_DB_PORT, 10) })
1414

1515
let sequelize;

models/patient.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ module.exports = (sequelize, DataTypes) => {
2121
allergies: DataTypes.STRING,
2222
medications: DataTypes.STRING
2323
}, {
24+
hooks: {
25+
beforeFind: async (options) => {
26+
console.error('beforeFind hook', options);
27+
if (options.__identity) {
28+
await sequelize.query(
29+
// Uncomment this line when using with Proxy
30+
'--SET IDENTITY TO ?', {
31+
replacements: [options.__identity],
32+
}
33+
);
34+
delete options.__identity;
35+
}
36+
},
37+
beforeFindAfterOptions: (options) => {
38+
// __identity is not present because it has been removed in the beforeFind hook
39+
console.error('beforeFindAfterOptions hook', options);
40+
},
41+
},
2442
sequelize,
2543
modelName: 'patient',
2644
});

server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ app.get(
7474

7575
const patients = await models.patient.findAll({
7676
order,
77-
where
77+
where,
78+
__identity: "some-long-token" // Set the JWT here
7879
});
7980

8081
res.status(200).json(patients);

tandem.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)