@ory/elements-react 1.0.0-next.1 → 1.0.0-next.3
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 +163 -7
- package/dist/index.js +19 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -13
- package/dist/index.mjs.map +1 -1
- package/dist/theme/default/index.css +0 -3
- package/dist/theme/default/index.css.map +1 -1
- package/dist/theme/default/index.js +29 -17
- package/dist/theme/default/index.js.map +1 -1
- package/dist/theme/default/index.mjs +39 -27
- package/dist/theme/default/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test-results/.last-run.json +0 -4
package/README.md
CHANGED
|
@@ -6,18 +6,174 @@
|
|
|
6
6
|
|
|
7
7
|
# @ory/elements-react
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a aria-label="NPM Version" href="https://www.npmjs.com/package/@ory/elements-react">
|
|
11
|
+
<img src="https://img.shields.io/npm/v/@ory/elements-react.svg?style=flat-square">
|
|
12
|
+
</a>
|
|
13
|
+
<a aria-label="License" href="https://github.com/ory/elements/blob/main/LICENSE">
|
|
14
|
+
<img src="https://img.shields.io/github/license/ory/elements?style=flat-square">
|
|
15
|
+
</a>
|
|
16
|
+
<a aria-label="Join Ory Slack community!" href="https://slack.ory.sh/">
|
|
17
|
+
<img src="https://img.shields.io/badge/Slack-Join%20the%20community!-4f46e5?style=flat-square&logo=slack&logoColor=eef2ff">
|
|
18
|
+
</a>
|
|
19
|
+
</p>
|
|
10
20
|
|
|
11
|
-
Ory Elements is a
|
|
12
|
-
|
|
13
|
-
|
|
21
|
+
Ory Elements is a set of components and functions tailored for easy integration
|
|
22
|
+
of Ory into your React application. It simplifies the process of adding
|
|
23
|
+
authentication and other identity features to your application using the Ory
|
|
24
|
+
Network.
|
|
14
25
|
|
|
15
|
-
|
|
26
|
+
## Documentation
|
|
16
27
|
|
|
17
|
-
|
|
28
|
+
Visit https://ory.sh/docs to see the full Ory documentation.
|
|
29
|
+
|
|
30
|
+
## Getting started
|
|
31
|
+
|
|
32
|
+
**Requirements**
|
|
33
|
+
|
|
34
|
+
- React `>= 18`
|
|
35
|
+
- Node.js `>= 18`
|
|
36
|
+
- **`@ory/client-fetch`** - fetch based version of ory client
|
|
18
37
|
|
|
19
|
-
|
|
38
|
+
**Installation**
|
|
20
39
|
|
|
21
40
|
```sh
|
|
22
41
|
npm install @ory/elements-react
|
|
23
42
|
```
|
|
43
|
+
|
|
44
|
+
> [!IMPORTANT]<br/>Please take a look at the
|
|
45
|
+
> [local develepmont documentation](https://www.ory.sh/docs/getting-started/local-development)
|
|
46
|
+
> \
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
Ory Elements provides components that can aggregate flow objects and display
|
|
51
|
+
user authentication flows based on the data.
|
|
52
|
+
|
|
53
|
+
To feed Ory Elements with flow data you need to use Ory client.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { frontendClient } from "@ory/client-fetch"
|
|
57
|
+
|
|
58
|
+
export function serverClientFrontend() {
|
|
59
|
+
// For testing purposes we're using Ory tunnel
|
|
60
|
+
return frontendClient("http://localhost:4000", {
|
|
61
|
+
headers: {
|
|
62
|
+
Accept: "application/json",
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Ory Network project setup
|
|
69
|
+
|
|
70
|
+
The Ory Identities APIs come with the ability to specify custom UI URLs. To make
|
|
71
|
+
sure, Ory knows about your custom UI, specify the URLs of your application on
|
|
72
|
+
https://console.ory.sh/projects/current/ui.
|
|
73
|
+
|
|
74
|
+
### Initializing a new flow
|
|
75
|
+
|
|
76
|
+
Initializing a new flow is done by navigating the user's page to the initialize
|
|
77
|
+
flow URL. After creating a new flow object, Ory will return a redirect to the
|
|
78
|
+
flow UI URL and, in some cases, return anti-CSRF cookies.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
export function init(params: QueryParams, flowType: FlowType) {
|
|
82
|
+
// Take advantage of the fact, that Ory handles the flow creation for us and redirects the user to the default return to automatically if they're logged in already.
|
|
83
|
+
return redirect(
|
|
84
|
+
"http://localhost:4000" +
|
|
85
|
+
"/self-service/" +
|
|
86
|
+
flowType.toString() +
|
|
87
|
+
"/browser?" +
|
|
88
|
+
new URLSearchParams(params).toString(),
|
|
89
|
+
RedirectType.replace,
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**FlowType** can be: `login`, `registration`, `recovery`, `verification`,
|
|
95
|
+
`settings` or `error`
|
|
96
|
+
|
|
97
|
+
To access & render the flow, on your flow page, you can use the `flow` query
|
|
98
|
+
parameter, that is included in the redirect. Use it to call the
|
|
99
|
+
[`getLoginFlow()`](https://www.ory.sh/docs/reference/api#tag/frontend/operation/getLoginFlow)
|
|
100
|
+
API.
|
|
101
|
+
|
|
102
|
+
**Full Example**:
|
|
103
|
+
|
|
104
|
+
````ts
|
|
105
|
+
export async function getOrCreateRegistrationFlow(
|
|
106
|
+
params: QueryParams
|
|
107
|
+
): Promise<RegistrationFlow> {
|
|
108
|
+
const onRestartFlow = () => init(params, FlowType.Registration);
|
|
109
|
+
|
|
110
|
+
// If flow ID doesn't exist in params simply trigget the init function.
|
|
111
|
+
if (!params.flow) {
|
|
112
|
+
return onRestartFlow();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return await serverClientFrontend()
|
|
116
|
+
// Passing the flow ID
|
|
117
|
+
.getRegistrationFlowRaw({ id: flow })
|
|
118
|
+
.then(res => res.value())
|
|
119
|
+
.catch(
|
|
120
|
+
// Ory Elements predefines the handleFlowError function to simplify error handling.
|
|
121
|
+
// You can define what should happen in each of these callbacks
|
|
122
|
+
handleFlowError({
|
|
123
|
+
onValidationError,
|
|
124
|
+
onRestartFlow,
|
|
125
|
+
onRedirect,
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
```
|
|
129
|
+
````
|
|
130
|
+
|
|
131
|
+
As soon as we have our flow data we can render the `<Registration/>` component
|
|
132
|
+
from `@ory/elements-react` package.
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
export default async function RegistrationPage({ searchParams }: PageProps) {
|
|
136
|
+
const flow = await getOrCreateRegistrationFlow(searchParams)
|
|
137
|
+
|
|
138
|
+
if (!flow) {
|
|
139
|
+
return <div>Flow not found</div>
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<Registration
|
|
144
|
+
flow={flow}
|
|
145
|
+
config={oryConfiguration}
|
|
146
|
+
components={ComponentOverrides}
|
|
147
|
+
/>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Styling
|
|
153
|
+
|
|
154
|
+
To include the default styles, add the following import to your app. Make sure
|
|
155
|
+
it's included on all pages, that use Ory Elements.
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import "@ory/elements-react/theme/styles.css"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Theming
|
|
162
|
+
|
|
163
|
+
Most styling can be overwritten, by providing your own custom CSS variables:
|
|
164
|
+
|
|
165
|
+
```css
|
|
166
|
+
:root {
|
|
167
|
+
/* To override the text color of the primary buttons */
|
|
168
|
+
--button-primary-fg-default: #fffeee;
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Package development
|
|
173
|
+
|
|
174
|
+
To develop and use the package `npm link` is recommended. To run the package in
|
|
175
|
+
watch mode use
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
npx nx run @ory/elements-react:dev
|
|
179
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -234,7 +234,7 @@ var require_react_is_development = __commonJS({
|
|
|
234
234
|
var ContextProvider = REACT_PROVIDER_TYPE;
|
|
235
235
|
var Element = REACT_ELEMENT_TYPE;
|
|
236
236
|
var ForwardRef = REACT_FORWARD_REF_TYPE;
|
|
237
|
-
var
|
|
237
|
+
var Fragment6 = REACT_FRAGMENT_TYPE;
|
|
238
238
|
var Lazy = REACT_LAZY_TYPE;
|
|
239
239
|
var Memo = REACT_MEMO_TYPE;
|
|
240
240
|
var Portal = REACT_PORTAL_TYPE;
|
|
@@ -293,7 +293,7 @@ var require_react_is_development = __commonJS({
|
|
|
293
293
|
exports.ContextProvider = ContextProvider;
|
|
294
294
|
exports.Element = Element;
|
|
295
295
|
exports.ForwardRef = ForwardRef;
|
|
296
|
-
exports.Fragment =
|
|
296
|
+
exports.Fragment = Fragment6;
|
|
297
297
|
exports.Lazy = Lazy;
|
|
298
298
|
exports.Memo = Memo;
|
|
299
299
|
exports.Portal = Portal;
|
|
@@ -4803,17 +4803,23 @@ var NodeInput = ({
|
|
|
4803
4803
|
}
|
|
4804
4804
|
);
|
|
4805
4805
|
case clientFetch.UiNodeInputAttributesTypeEnum.Hidden:
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4806
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4807
|
+
isCurrentIdentifier && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4808
|
+
Components.CurrentIdentifierButton,
|
|
4809
|
+
{
|
|
4810
|
+
attributes: attrs,
|
|
4811
|
+
node
|
|
4812
|
+
}
|
|
4813
|
+
),
|
|
4814
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4815
|
+
Components.Input,
|
|
4816
|
+
{
|
|
4817
|
+
attributes: attrs,
|
|
4818
|
+
node,
|
|
4819
|
+
onClick: handleClick
|
|
4820
|
+
}
|
|
4821
|
+
)
|
|
4822
|
+
] });
|
|
4817
4823
|
default:
|
|
4818
4824
|
if (isPinCodeInput) {
|
|
4819
4825
|
return /* @__PURE__ */ jsxRuntime.jsx(Components.Label, { attributes: attrs, node, children: /* @__PURE__ */ jsxRuntime.jsx(
|