1
1
import * as React from "react" ;
2
+ import Helmet from "react-helmet" ;
2
3
import { css } from "emotion" ;
3
4
import styled from "@emotion/styled" ;
4
- import Helmet from "react-helmet" ;
5
- import authErrorImg from "./SecureRouteError.svg" ;
6
5
import { Typography } from "@webiny/ui/Typography" ;
7
6
import { useTenancy } from "@webiny/app-tenancy/hooks/useTenancy" ;
7
+ import { useSecurity } from "@webiny/app-security" ;
8
+ import { makeComposable } from "@webiny/app-admin" ;
9
+ import authErrorImg from "./SecureRouteError.svg" ;
8
10
9
11
const ContentWrapper = styled ( "div" ) ( {
10
12
display : "block" ,
@@ -31,18 +33,29 @@ const styles = {
31
33
} )
32
34
} ;
33
35
34
- export const NotAuthorizedError = ( ) => {
36
+ export interface ImageProps {
37
+ className ?: string ;
38
+ alt ?: string ;
39
+ }
40
+
41
+ const Image = ( { className = styles . authErrorImgStyle , alt = "Not Authorized" } : ImageProps ) => {
42
+ return < img className = { className } src = { authErrorImg } alt = { alt } /> ;
43
+ } ;
44
+
45
+ const NotAuthorizedComponent = makeComposable ( "NotAuthorizedError" , ( ) => {
35
46
const { setTenant } = useTenancy ( ) ;
47
+ const { identity } = useSecurity ( ) ;
48
+
49
+ const defaultTenant = identity && identity . defaultTenant ? identity . defaultTenant . id : null ;
36
50
37
51
const resetTenant = ( ) : void => {
38
- setTenant ( null ) ;
52
+ setTenant ( defaultTenant ) ;
39
53
} ;
40
54
41
55
return (
42
56
< ContentWrapper >
43
57
< Helmet title = { "Not authorized!" } />
44
-
45
- < img className = { styles . authErrorImgStyle } src = { authErrorImg } alt = "Not Authorized" />
58
+ < Image />
46
59
47
60
< Typography use = { "body1" } className = { styles . bodyStyle } >
48
61
You are not authorized to access this tenant!
@@ -57,4 +70,6 @@ export const NotAuthorizedError = () => {
57
70
</ a >
58
71
</ ContentWrapper >
59
72
) ;
60
- } ;
73
+ } ) ;
74
+
75
+ export const NotAuthorizedError = Object . assign ( NotAuthorizedComponent , { Image } ) ;
0 commit comments