Skip to content

Commit 38895f2

Browse files
Add auth guard routing before uploading
1 parent 9f8ae87 commit 38895f2

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

app/lib/pages/code/footer-action/next-upload-button.tsx

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import { BlackButton } from "../../../components/style/global-style";
44
import { registerScene } from "../../../scene-view";
55
import { PluginSdk } from "@plugin-sdk/app";
66
import type { IReflectNodeReference } from "@design-sdk/core/nodes/lignt";
7+
import { isAuthenticated } from "../../../auth";
8+
import { useHistory } from "react-router-dom";
79

810
export function NextUploadButton(props: {
911
disabled?: boolean;
1012
scene?: IReflectNodeReference;
1113
app?: any;
1214
}) {
1315
const [isLoading, setIsLoading] = useState(false);
16+
const history = useHistory();
1417

1518
const register = async () => {
1619
setIsLoading(true);
@@ -38,27 +41,36 @@ export function NextUploadButton(props: {
3841
},
3942
});
4043
};
44+
45+
const onNextClick = async () => {
46+
const authenticated = await isAuthenticated();
47+
if (!authenticated) {
48+
PluginSdk.notify("Let's Sign in first");
49+
history.push("/signin");
50+
return;
51+
}
52+
53+
// if authenticated, we can procceed to next step finally. ;)
54+
register()
55+
.then((d) => {
56+
open(buildOpenUrlForRegisteredScene(d.id));
57+
})
58+
.catch((e) => {
59+
console.error("error while registering scene", e);
60+
PluginSdk.notify(
61+
"Oops. something went wrong. pplease try again. ;)",
62+
3
63+
);
64+
})
65+
.finally(() => {
66+
setIsLoading(false);
67+
});
68+
};
69+
4170
return (
4271
<NextStepButton
4372
disabled={props.disabled || isLoading}
44-
onClick={() => {
45-
register()
46-
.then((d) => {
47-
open(buildOpenUrlForRegisteredScene(d.id));
48-
})
49-
.catch((e) => {
50-
console.error("error while registering scene", e);
51-
PluginSdk.notify(
52-
"Oops. something went wrong. pplease try again. ;)",
53-
3
54-
);
55-
})
56-
.finally(() => {
57-
setIsLoading(false);
58-
});
59-
// upload
60-
// TODO: the button component should be passed from outer side.
61-
}}
73+
onClick={onNextClick}
6274
>
6375
Next
6476
</NextStepButton>
@@ -72,7 +84,7 @@ function buildOpenUrlForRegisteredScene(sceneId: string) {
7284
const NextStepButton = styled.button`
7385
${BlackButton}
7486
/* 2/3 size. 12 is wrapper padding */
75-
width: calc(66.666% - 12px);
87+
width: calc(66.666% - 12px); /* FIXME: stupid! */
7688
7789
&:hover {
7890
color: #fff;

0 commit comments

Comments
 (0)