session-sync-auth-site 0.5.1 → 0.5.2

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 CHANGED
@@ -115,7 +115,8 @@ app.post(`create-user`, (req, res, next) => {
115
115
  app.post(`get-login-link`, (req, res, next) => {
116
116
  const loginLink = await getLoginLink({
117
117
  email: req.body.email,
118
- redirectUrl: req.body.redirectUrl, // optional
118
+ redirectUrl: req.body.redirectUrl, // must begin with the frontend domain (default: req.headers.origin)
119
+ origin: `https://my-backend-domain.com`, // default: req.headers.origin
119
120
  req,
120
121
  })
121
122
  res.send({ loginLink })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "session-sync-auth-site",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "main": "src/index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -4,11 +4,13 @@ const jwt = require('jsonwebtoken')
4
4
  const getLoginLink = async ({
5
5
  email,
6
6
  redirectUrl, // defaults to req.headers.origin
7
+ origin, // defaults to req.headers.origin
7
8
  req, // either this or `setup` is required
8
9
  setup, // keys: siteId, authDomain, and jwtSecret
9
10
  }={}) => {
10
11
 
11
12
  redirectUrl = redirectUrl || req.headers.origin
13
+ origin = origin || req.headers.origin
12
14
 
13
15
  const {
14
16
  siteId,
@@ -17,7 +19,6 @@ const getLoginLink = async ({
17
19
  protocol=req.sessionSyncAuthProtocol || `https`,
18
20
  } = setup || await req.getSessionSyncAuthSetupInfo()
19
21
 
20
- const origin = (redirectUrl.match(/^https?:\/\/[^/]+/, '') || {})[0]
21
22
  const loggedInRedirectUrl = `${redirectUrl}${/\?/.test(redirectUrl) ? `&` : `?`}action=successfulLogin&origin=${encodeURIComponent(origin)}&accessToken=ACCESS_TOKEN`
22
23
 
23
24
  const getLoginLinkResult = await fetch(