-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAuthentication.context.js
73 lines (68 loc) · 2.04 KB
/
Authentication.context.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React from 'react';
import PropTypes from 'prop-types';
import { useAuthentication } from '.';
export const AuthenticationContext = React.createContext();
export function AuthenticationContextProvider({
config: _config,
messages,
authentication,
onAuthentication,
loadAuthentication,
saveAuthentication,
children,
onError,
}) {
const {
state, actions, component, config,
} = useAuthentication({
authentication,
onAuthentication,
config: _config,
messages,
loadAuthentication,
saveAuthentication,
onError,
});
const context = {
state,
actions,
component,
config,
};
return (
<AuthenticationContext.Provider value={context}>
{children}
</AuthenticationContext.Provider>
);
};
AuthenticationContextProvider.propTypes = {
/** Pass a previously returned authentication object to bypass login. */
authentication: PropTypes.shape({
user: PropTypes.object.isRequired,
token: PropTypes.object.isRequired,
config: PropTypes.object.isRequired,
remember: PropTypes.bool,
}),
/** Callback function to propogate the user/token used for API Authentication. */
onAuthentication: PropTypes.func,
/** Configuration to pass through to the Authentication component. */
/** Override the default text and errors. Must override all or none. */
messages: PropTypes.shape({
actionText: PropTypes.string.isRequired,
genericError: PropTypes.string.isRequired,
usernameError: PropTypes.string.isRequired,
passwordError: PropTypes.string.isRequired,
}),
config: PropTypes.shape({
/** The Gitea server to use when authenticating. */
server: PropTypes.string.isRequired,
/** The id of the token to create/retrieve that is used for the app. */
tokenid: PropTypes.string.isRequired,
}),
/** Callback function to persist authentication. */
saveAuthentication: PropTypes.func,
/** Callback function to retrieve persisted authentication. */
loadAuthentication: PropTypes.func,
/** optional callback for error */
onError: PropTypes.func,
};