@longline/aqua-ui 1.0.15 → 1.0.17

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.
@@ -1 +1 @@
1
- export * from './SecondaryButton';
1
+ export { SecondaryButton } from './SecondaryButton';
@@ -1 +1 @@
1
- export * from './SecondaryButton';
1
+ export { SecondaryButton } from './SecondaryButton';
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@longline/aqua-ui",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "AquaUI",
5
5
  "author": "Alexander van Oostenrijk / Longline Environment",
6
6
  "license": "Commercial",
7
7
  "homepage": "https://github.com/henck/aqua-ui#readme",
8
- "main": "index.js",
9
- "module": "index.js",
10
- "types": "index.d.ts",
8
+ "main": "/index.js",
9
+ "module": "/index.js",
10
+ "types": "/index.d.ts",
11
11
  "repository": {
12
12
  "type": "git",
13
13
  "url": "git+https://github.com/henck/aqua-ui.git"
@@ -0,0 +1,26 @@
1
+ import * as React from 'react';
2
+ interface IProps {
3
+ children?: React.ReactNode;
4
+ }
5
+ /**
6
+ * `Auth` serves as an authentication and authorization context. It wraps an application,
7
+ * providing it with the `useAuth` hook. This hook is used to determine if a user is currently
8
+ * authenticated, and redirect to a different route if necessary.
9
+ *
10
+ * Wrap an application:
11
+ *
12
+ * ```tsx
13
+ * <Auth>
14
+ * ...
15
+ * </Auth>
16
+ * ```
17
+ *
18
+ * In the application, use `useAuth`:
19
+ *
20
+ * ```tsx
21
+ * const auth = useAuth();
22
+ * auth.signin("access", "refresh");
23
+ * ```
24
+ */
25
+ declare const Auth: (props: IProps) => React.JSX.Element;
26
+ export { Auth };
@@ -0,0 +1,63 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import * as React from 'react';
13
+ import { AuthContext } from './AuthContext';
14
+ /**
15
+ * `Auth` serves as an authentication and authorization context. It wraps an application,
16
+ * providing it with the `useAuth` hook. This hook is used to determine if a user is currently
17
+ * authenticated, and redirect to a different route if necessary.
18
+ *
19
+ * Wrap an application:
20
+ *
21
+ * ```tsx
22
+ * <Auth>
23
+ * ...
24
+ * </Auth>
25
+ * ```
26
+ *
27
+ * In the application, use `useAuth`:
28
+ *
29
+ * ```tsx
30
+ * const auth = useAuth();
31
+ * auth.signin("access", "refresh");
32
+ * ```
33
+ */
34
+ var Auth = function (props) {
35
+ var getInitialState = function () {
36
+ // Try to load Auth from session storage.
37
+ var authStr = sessionStorage.getItem('auth');
38
+ var authData = authStr ? JSON.parse(authStr) : {};
39
+ var initialState = {
40
+ access_token: null,
41
+ refresh_token: null
42
+ };
43
+ initialState = __assign(__assign({}, initialState), authData);
44
+ return initialState;
45
+ };
46
+ var _a = React.useState(getInitialState()), data = _a[0], setData = _a[1];
47
+ var signin = function (access_token, refresh_token) {
48
+ var newData = {
49
+ access_token: access_token,
50
+ refresh_token: refresh_token
51
+ };
52
+ setData(newData);
53
+ // Store auth in session:
54
+ sessionStorage.setItem('auth', JSON.stringify(newData));
55
+ };
56
+ var signout = function () {
57
+ setData({ access_token: null, refresh_token: null });
58
+ // Remove auth from session:
59
+ sessionStorage.removeItem('auth');
60
+ };
61
+ return (React.createElement(AuthContext.Provider, { value: __assign({ signin: signin, signout: signout }, data) }, props.children));
62
+ };
63
+ export { Auth };
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ interface IAuth {
3
+ access_token: string;
4
+ refresh_token: string;
5
+ }
6
+ interface IAuthContext extends IAuth {
7
+ signin: (access_token: string, refresh_token: string) => void;
8
+ signout: () => void;
9
+ }
10
+ declare const AuthContext: React.Context<IAuthContext>;
11
+ export { AuthContext, IAuth, IAuthContext };
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ var AuthContext = React.createContext(null);
3
+ export { AuthContext };
@@ -0,0 +1,2 @@
1
+ export * from './Auth';
2
+ export * from './useAuth';
@@ -0,0 +1,2 @@
1
+ export * from './Auth';
2
+ export * from './useAuth';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Returns the instance of the `Auth` state.
3
+ */
4
+ declare const useAuth: () => import("./AuthContext").IAuthContext;
5
+ export { useAuth };
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ import { AuthContext } from "./AuthContext";
3
+ /**
4
+ * Returns the instance of the `Auth` state.
5
+ */
6
+ var useAuth = function () {
7
+ return React.useContext(AuthContext);
8
+ };
9
+ export { useAuth };