@aglyn/shared-util-next 1.0.0-beta.143 → 1.0.0-beta.144
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 +54 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,3 +1,55 @@
|
|
|
1
|
-
# shared-util-next
|
|
1
|
+
# @aglyn/shared-util-next
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React hooks and helpers for carrying a `?continue=` return URL through a Next.js App Router sign-in flow without creating an open redirect. It is used by Aglyn's console sign-in pages and is usable in any App Router app.
|
|
4
|
+
|
|
5
|
+
> Beta. Published from the Aglyn monorepo under the `beta` dist-tag; APIs can change between beta releases.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
npm install @aglyn/shared-util-next@beta
|
|
10
|
+
|
|
11
|
+
Peer dependencies: `next` (`16.3.3`) and `react` (`^19.2.8`).
|
|
12
|
+
|
|
13
|
+
## What's in it
|
|
14
|
+
|
|
15
|
+
One client module (`'use client'`), `use-continue-url`, re-exported from the package root:
|
|
16
|
+
|
|
17
|
+
- `useContinueUrl()` - returns `[encoded, decoded, pushNext]`: the current pathname URL-encoded (to put into a link to the sign-in page), the validated `continue` value from the query string (or `''`), and a function that navigates to it.
|
|
18
|
+
- `useContinueUrlDecoded()` - `[decoded, pushNext]`. `pushNext(url = '/')` goes to the continue URL when there is a safe one, otherwise to `url`. Relative targets use `router.push`; absolute ones use `window.location.assign`.
|
|
19
|
+
- `useContinueUrlEncoded()` - the encoded current pathname only.
|
|
20
|
+
- `useContinueHref(path)` - an `href` for a link out of the current page that keeps the `continue` value. Reads only `useSearchParams`, not the router.
|
|
21
|
+
- `withContinueUrl(path, continueUrl)` - the same, as a plain function. Unsafe or empty values append nothing.
|
|
22
|
+
- `isSafeContinueUrl(url)` - the predicate behind all of the above.
|
|
23
|
+
- `ContinueParamName` (`'continue'`) and `continueParam(value)`.
|
|
24
|
+
|
|
25
|
+
A continue URL is accepted when it is a relative path that resolves onto the current origin (checked with `isSameOriginPath` from `@aglyn/shared-util-http/safe-redirect`), or an absolute `https:` URL whose host is the workspace domain or a subdomain of it. The workspace domain comes from `NEXT_PUBLIC_WORKSPACE_DOMAIN` and defaults to `aglyn.com`, so set that variable when you use this outside Aglyn. Everything else is treated as absent.
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
'use client'
|
|
31
|
+
|
|
32
|
+
import { useContinueHref, useContinueUrlDecoded } from '@aglyn/shared-util-next'
|
|
33
|
+
|
|
34
|
+
export function AfterSignIn() {
|
|
35
|
+
const [, pushNext] = useContinueUrlDecoded()
|
|
36
|
+
const ssoHref = useContinueHref('/sso')
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<>
|
|
40
|
+
<button onClick={() => pushNext('/dashboard')}>Continue</button>
|
|
41
|
+
<a href={ssoHref}>Use single sign-on</a>
|
|
42
|
+
</>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The hooks call `useSearchParams`, so render them under a `Suspense` boundary as Next.js requires.
|
|
48
|
+
|
|
49
|
+
## How it fits
|
|
50
|
+
|
|
51
|
+
A `shared` package: generic, with no knowledge of Aglyn's model. Shared packages may only import other shared packages; this one depends on `@aglyn/shared-util-http`. No other library in the monorepo depends on it; the console app uses it directly.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
Apache-2.0. Source: https://github.com/aglyn/aglyn/tree/main/libs/shared/util/next
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/shared-util-next",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.144",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"./package.json": "./package.json"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@aglyn/shared-util-http": "1.0.0-beta.
|
|
27
|
+
"@aglyn/shared-util-http": "1.0.0-beta.144",
|
|
28
28
|
"@swc/helpers": "0.5.23"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|