@nxgt/janus 0.16.0 → 0.16.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.
@@ -30,6 +30,12 @@ const session = await auth.stepUp.confirm(request, issued.challenge, code);
30
30
  session.authenticatedAt; // now: the action goes through for the next ten minutes
31
31
  ```
32
32
 
33
+ `sendMail` stands for your own sending. With
34
+ [`@nxgt/janus-mail`](https://www.npmjs.com/package/@nxgt/janus-mail) 0.8,
35
+ `mail.stepUp(issued, { name, locale })` sends it — "Your confirmation code",
36
+ in English or French — see [Sending the code with
37
+ `@nxgt/janus-mail`](#sending-the-code-with-nxgtjanus-mail).
38
+
33
39
  A step-up is two requests, as a sign-in by code is: one issues the code, the
34
40
  other takes it and stamps the session. It **opens no session** and hands out
35
41
  no new token: the session the request presents is the one confirmed, which
@@ -110,6 +116,31 @@ if (issued.via === 'email') {
110
116
  return Response.json({ challenge: issued.challenge, via: issued.via });
111
117
  ```
112
118
 
119
+ ### Sending the code with `@nxgt/janus-mail`
120
+
121
+ `@nxgt/janus-mail`'s `mail.stepUp` takes what `request` answered, once
122
+ narrowed to `via: 'email'`, and sends it to `issued.email`: a greeting by
123
+ name, the code, how long it lasts — "This code expires in 10 minutes." —
124
+ and a **Secure my account** button to its `links.secureAccount()`, for a
125
+ user who asked for nothing. It reads the code, the address and `expiresAt`,
126
+ never the challenge:
127
+
128
+ ```ts
129
+ import { janusMail } from '@nxgt/janus-mail';
130
+
131
+ const mail = janusMail({ mailer, from: 'noreply@acme.example', brand: 'Acme', links });
132
+
133
+ const issued = await auth.stepUp.request(current.user);
134
+ if (issued.via === 'email') {
135
+ await mail.stepUp(issued, { name: current.user.name, locale: current.user.locale });
136
+ }
137
+ return Response.json({ challenge: issued.challenge, via: issued.via });
138
+ ```
139
+
140
+ An un-narrowed answer is a compile error there, and a `via: 'secondFactor'`
141
+ passed from JavaScript a `TypeError`: an app's step-up has nothing to send.
142
+ See its [sending guide](https://github.com/softistx/nxgt-janus/blob/develop/packages/janus-mail/docs/guide/sending.md#stepupissued-to-options).
143
+
113
144
  **One step-up is live per user**: a request spends every step-up issued
114
145
  before it. The challenge lapses after ten minutes by default —
115
146
  `janus({ tokens: { stepUp: '5m' } })` changes it.
@@ -176,3 +207,5 @@ calls are traced like every other flow.
176
207
  - [Signing in with an e-mailed code](sign-in-code.md) — the same six digits,
177
208
  to sign in.
178
209
  - [Errors](errors.md) — every code and its status.
210
+ - [`@nxgt/janus-mail`](https://github.com/softistx/nxgt-janus/blob/develop/packages/janus-mail/docs/guide/sending.md#stepupissued-to-options)
211
+ — `mail.stepUp`, the step-up's e-mail.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxgt/janus",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Embeddable, type-safe identities and permissions: bring your own database",
5
5
  "license": "MIT",
6
6
  "type": "module",