diff --git a/package.json b/package.json index 2f38138a..577fc05a 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "husky": "^7.0.4", "import-sort-style-module": "^6.0.0", "iso-639-1": "^2.1.10", - "lemmy-js-client": "0.15.0-rc.1", + "lemmy-js-client": "0.15.0-rc.3", "lint-staged": "^12.1.2", "mini-css-extract-plugin": "^2.4.5", "node-fetch": "^2.6.1", diff --git a/src/server/index.tsx b/src/server/index.tsx index 5bf79f17..cedb22da 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -91,7 +91,11 @@ server.get("/*", async (req, res) => { if (routeData[0] && routeData[0].error) { let errCode = routeData[0].error; console.error(errCode); - return res.redirect(`/404?err=${errCode}`); + if (errCode == "instance_is_private") { + return res.redirect(`/login`); + } else { + return res.redirect(`/404?err=${errCode}`); + } } let isoData: IsoData = { diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index f44d4cc0..d1451451 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -239,6 +239,7 @@ export class Home extends Component { sort: SortType.Hot, limit: 6, }; + setOptionalAuth(trendingCommunitiesForm, req.auth); promises.push(req.client.listCommunities(trendingCommunitiesForm)); return promises; diff --git a/src/shared/components/home/password-change.tsx b/src/shared/components/person/password-change.tsx similarity index 100% rename from src/shared/components/home/password-change.tsx rename to src/shared/components/person/password-change.tsx diff --git a/src/shared/components/person/verify-email.tsx b/src/shared/components/person/verify-email.tsx new file mode 100644 index 00000000..bfcca3f7 --- /dev/null +++ b/src/shared/components/person/verify-email.tsx @@ -0,0 +1,98 @@ +import { Component } from "inferno"; +import { + LoginResponse, + SiteView, + UserOperation, + VerifyEmail as VerifyEmailForm, +} from "lemmy-js-client"; +import { Subscription } from "rxjs"; +import { i18n } from "../../i18next"; +import { UserService, WebSocketService } from "../../services"; +import { + isBrowser, + setIsoData, + toast, + wsClient, + wsJsonToRes, + wsSubscribe, + wsUserOp, +} from "../../utils"; +import { HtmlTags } from "../common/html-tags"; + +interface State { + verifyEmailForm: VerifyEmailForm; + site_view: SiteView; +} + +export class VerifyEmail extends Component { + private isoData = setIsoData(this.context); + private subscription: Subscription; + + emptyState: State = { + verifyEmailForm: { + token: this.props.match.params.token, + }, + site_view: this.isoData.site_res.site_view, + }; + + constructor(props: any, context: any) { + super(props, context); + + this.state = this.emptyState; + + this.parseMessage = this.parseMessage.bind(this); + this.subscription = wsSubscribe(this.parseMessage); + } + + componentDidMount() { + WebSocketService.Instance.send( + wsClient.verifyEmail(this.state.verifyEmailForm) + ); + } + + componentWillUnmount() { + if (isBrowser()) { + this.subscription.unsubscribe(); + } + } + + get documentTitle(): string { + return `${i18n.t("verify_email")} - ${this.state.site_view.site.name}`; + } + + render() { + return ( +
+ +
+
+
{i18n.t("verify_email")}
+
+
+
+ ); + } + + parseMessage(msg: any) { + let op = wsUserOp(msg); + console.log(msg); + if (msg.error) { + toast(i18n.t(msg.error), "danger"); + this.setState(this.state); + this.props.history.push("/"); + return; + } else if (op == UserOperation.VerifyEmail) { + let data = wsJsonToRes(msg).data; + if (data.jwt) { + toast(i18n.t("email_verified")); + this.state = this.emptyState; + this.setState(this.state); + UserService.Instance.login(data); + this.props.history.push("/"); + } + } + } +} diff --git a/src/shared/routes.ts b/src/shared/routes.ts index 71ab79ed..86c0b3c3 100644 --- a/src/shared/routes.ts +++ b/src/shared/routes.ts @@ -6,15 +6,16 @@ import { AdminSettings } from "./components/home/admin-settings"; import { Home } from "./components/home/home"; import { Instances } from "./components/home/instances"; import { Login } from "./components/home/login"; -import { PasswordChange } from "./components/home/password-change"; import { Setup } from "./components/home/setup"; import { Signup } from "./components/home/signup"; import { Modlog } from "./components/modlog"; import { Inbox } from "./components/person/inbox"; +import { PasswordChange } from "./components/person/password-change"; import { Profile } from "./components/person/profile"; import { RegistrationApplications } from "./components/person/registration-applications"; import { Reports } from "./components/person/reports"; import { Settings } from "./components/person/settings"; +import { VerifyEmail } from "./components/person/verify-email"; import { CreatePost } from "./components/post/create-post"; import { Post } from "./components/post/post"; import { CreatePrivateMessage } from "./components/private_message/create-private-message"; @@ -148,5 +149,9 @@ export const routes: IRoutePropsWithFetch[] = [ path: `/password_change/:token`, component: PasswordChange, }, + { + path: `/verify_email/:token`, + component: VerifyEmail, + }, { path: `/instances`, component: Instances }, ]; diff --git a/yarn.lock b/yarn.lock index ae68871a..21e32d2c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4997,10 +4997,10 @@ lcid@^1.0.0: dependencies: invert-kv "^1.0.0" -lemmy-js-client@0.15.0-rc.1: - version "0.15.0-rc.1" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.15.0-rc.1.tgz#7f5f0f069c76c5377a2a8654ce3a10563f405e14" - integrity sha512-Dgq7G2jGLURoswV40DfUNNvxQ/Dg8Jkz9jarwJuOMmBF9MfM/wD1nlaPtvMHlxePXtgDc8Y/Ig84k1OEF8Myqw== +lemmy-js-client@0.15.0-rc.3: + version "0.15.0-rc.3" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.15.0-rc.3.tgz#acc762981f2bbd4381857d12bf576b0d85451c4f" + integrity sha512-Yk1Y32ILc2E/eTfnjtvZBoPGwPUqokPKlouOpng7cJohFMqZUWocy8Z3yK+tx81/l0Lss9RT4HaqsRmvmEmfJw== levn@^0.4.1: version "0.4.1"