session-sync-auth-site 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/package.json +1 -1
- package/src/authenticate.js +12 -0
- package/src/sessionSyncAuthFrontend.js +6 -6
package/README.md
CHANGED
|
@@ -56,6 +56,15 @@ app.use(authenticate({
|
|
|
56
56
|
// Example:
|
|
57
57
|
// updated_at: 'updatedAt',
|
|
58
58
|
},
|
|
59
|
+
extraUserTableSelectValues: {
|
|
60
|
+
// Use this when the user table id column is not unique.
|
|
61
|
+
// (Often the case with a multi-tenacy setup.)
|
|
62
|
+
// In such a case, add other WHERE parameters here to combine with
|
|
63
|
+
// the id column such that combination is unique.
|
|
64
|
+
// Note: These parameters will typically coincide with `extraUserTableValues` below.
|
|
65
|
+
// Example:
|
|
66
|
+
// tenantId: 34,
|
|
67
|
+
},
|
|
59
68
|
sessionTableColNameMap: {},
|
|
60
69
|
}))
|
|
61
70
|
```
|
|
@@ -75,6 +84,8 @@ setUpSessionSyncAuthRoutes({
|
|
|
75
84
|
authDomain,
|
|
76
85
|
jwtSecret,
|
|
77
86
|
extraUserTableValues, // optional
|
|
87
|
+
// Note: In a multi-tenancy setup, `extraUserTableValues` should
|
|
88
|
+
// typically coincide with `extraUserTableSelectValues` above.
|
|
78
89
|
}
|
|
79
90
|
},
|
|
80
91
|
protocol: 'https',
|
package/package.json
CHANGED
package/src/authenticate.js
CHANGED
|
@@ -5,6 +5,7 @@ const authenticate = ({
|
|
|
5
5
|
sessionTableName='sessions',
|
|
6
6
|
userTableColNameMap={},
|
|
7
7
|
sessionTableColNameMap={},
|
|
8
|
+
extraUserTableSelectValues={}, // for when the users.id col is not unique
|
|
8
9
|
...connectionInfo // connectionObj or connectionStr
|
|
9
10
|
}) => (
|
|
10
11
|
async (req, res, next) => {
|
|
@@ -65,11 +66,22 @@ const authenticate = ({
|
|
|
65
66
|
|
|
66
67
|
WHERE
|
|
67
68
|
s.\`${sessionTableAccessToken}\` = :accessToken
|
|
69
|
+
${
|
|
70
|
+
Object.keys(extraUserTableSelectValues)
|
|
71
|
+
.map(key => {
|
|
72
|
+
const safeKey = key.replace(/[`\s]/g, '')
|
|
73
|
+
return (
|
|
74
|
+
`AND \`${safeKey}\` = :${safeKey}`
|
|
75
|
+
)
|
|
76
|
+
})
|
|
77
|
+
.join('\n')
|
|
78
|
+
}
|
|
68
79
|
|
|
69
80
|
LIMIT 1
|
|
70
81
|
|
|
71
82
|
`,
|
|
72
83
|
{
|
|
84
|
+
...extraUserTableSelectValues,
|
|
73
85
|
accessToken,
|
|
74
86
|
},
|
|
75
87
|
))[0]
|
|
@@ -43,18 +43,18 @@
|
|
|
43
43
|
return queryStringAddOn
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const logIn = async ({ origin=defaultOrigin, extraQueryParamsForCallbacks,
|
|
47
|
-
const cancelRedirectUrl = `${
|
|
48
|
-
const loggedInRedirectUrl = `${
|
|
46
|
+
const logIn = async ({ origin=defaultOrigin, extraQueryParamsForCallbacks, loggedInRedirectHref }={}) => {
|
|
47
|
+
const cancelRedirectUrl = `${location.href.replace(/\?.*$/, '')}?action=canceledLogin&origin=${encodeURIComponent(origin)}${getQueryStringAddOn(extraQueryParamsForCallbacks)}`
|
|
48
|
+
const loggedInRedirectUrl = `${loggedInRedirectHref || location.href.replace(/\?.*$/, '')}?action=successfulLogin&origin=${encodeURIComponent(origin)}&accessToken=ACCESS_TOKEN${getQueryStringAddOn(extraQueryParamsForCallbacks)}`
|
|
49
49
|
|
|
50
50
|
const queryString = `cancelRedirectUrl=${encodeURIComponent(cancelRedirectUrl)}&loggedInRedirectUrl=${encodeURIComponent(loggedInRedirectUrl)}`
|
|
51
51
|
|
|
52
52
|
window.location = `${origin}/log-in?${queryString}`
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const updateAccount = async ({ origin=defaultOrigin, extraQueryParamsForCallbacks,
|
|
56
|
-
const cancelRedirectUrl = `${
|
|
57
|
-
const updatedRedirectUrl = `${
|
|
55
|
+
const updateAccount = async ({ origin=defaultOrigin, extraQueryParamsForCallbacks, updatedRedirectHref }={}) => {
|
|
56
|
+
const cancelRedirectUrl = `${location.href.replace(/\?.*$/, '')}?action=canceledAccountUpdate&origin=${encodeURIComponent(origin)}${getQueryStringAddOn(extraQueryParamsForCallbacks)}`
|
|
57
|
+
const updatedRedirectUrl = `${updatedRedirectHref || location.href.replace(/\?.*$/, '')}?action=successfulAccountUpdate&origin=${encodeURIComponent(origin)}${getQueryStringAddOn(extraQueryParamsForCallbacks)}`
|
|
58
58
|
|
|
59
59
|
const queryString = `cancelRedirectUrl=${encodeURIComponent(cancelRedirectUrl)}&updatedRedirectUrl=${encodeURIComponent(updatedRedirectUrl)}`
|
|
60
60
|
|