2021-01-26 22:04:54 +00:00
|
|
|
import { parse as parseQs } from "qs";
|
2021-12-17 11:10:54 +00:00
|
|
|
import React, { useContext } from "react";
|
2021-01-26 22:04:54 +00:00
|
|
|
import { Route, RouteComponentProps, Switch } from "react-router-dom";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-09-03 13:42:15 +00:00
|
|
|
import Layout from "./components/Layout";
|
2021-12-17 11:10:54 +00:00
|
|
|
import { UserContext as Context } from "./types";
|
2021-01-26 22:04:54 +00:00
|
|
|
import {
|
|
|
|
LoginUrlQueryParams,
|
2019-09-02 19:23:37 +00:00
|
|
|
newPasswordPath,
|
|
|
|
passwordResetPath,
|
2022-06-21 09:36:55 +00:00
|
|
|
passwordResetSuccessPath,
|
2019-09-02 19:23:37 +00:00
|
|
|
} from "./urls";
|
2021-01-26 22:04:54 +00:00
|
|
|
import LoginViewComponent from "./views/Login";
|
2019-09-02 19:23:37 +00:00
|
|
|
import NewPassword from "./views/NewPassword";
|
|
|
|
import ResetPassword from "./views/ResetPassword";
|
|
|
|
import ResetPasswordSuccess from "./views/ResetPasswordSuccess";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2021-01-26 22:04:54 +00:00
|
|
|
const LoginView: React.FC<RouteComponentProps<any>> = () => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: LoginUrlQueryParams = qs;
|
|
|
|
|
|
|
|
return <LoginViewComponent params={params} />;
|
|
|
|
};
|
|
|
|
|
2021-12-17 11:10:54 +00:00
|
|
|
export const UserContext = React.createContext<Context>({
|
2019-06-19 14:40:52 +00:00
|
|
|
login: undefined,
|
2021-01-26 22:04:54 +00:00
|
|
|
loginByExternalPlugin: undefined,
|
2019-09-02 19:23:37 +00:00
|
|
|
logout: undefined,
|
2021-01-26 22:04:54 +00:00
|
|
|
requestLoginByExternalPlugin: undefined,
|
2021-12-17 11:10:54 +00:00
|
|
|
authenticating: false,
|
2022-06-21 09:36:55 +00:00
|
|
|
authenticated: false,
|
2019-06-19 14:40:52 +00:00
|
|
|
});
|
|
|
|
|
2020-07-21 16:49:20 +00:00
|
|
|
const AuthRouter: React.FC = () => (
|
2019-09-03 13:42:15 +00:00
|
|
|
<Layout>
|
|
|
|
<Switch>
|
|
|
|
<Route path={passwordResetSuccessPath} component={ResetPasswordSuccess} />
|
|
|
|
<Route path={passwordResetPath} component={ResetPassword} />
|
2020-07-21 16:49:20 +00:00
|
|
|
<Route path={newPasswordPath} component={NewPassword} />
|
2019-09-03 13:42:15 +00:00
|
|
|
<Route component={LoginView} />
|
|
|
|
</Switch>
|
|
|
|
</Layout>
|
2019-09-02 19:23:37 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
AuthRouter.displayName = "AuthRouter";
|
|
|
|
export default AuthRouter;
|
2019-09-03 13:42:15 +00:00
|
|
|
|
|
|
|
export * from "./utils";
|
2021-12-17 11:10:54 +00:00
|
|
|
export const useUser = () => useContext(UserContext);
|