From 2c3d4f86c871ee585fc796c03dbd51bb135d1668 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 29 Jan 2024 17:01:52 +0800 Subject: [PATCH] :sparkles: Redirect uri --- pkg/models/clients.go | 4 ++++ view/src/layouts/RootLayout.tsx | 12 ++++++++++++ view/src/pages/auth/login.tsx | 8 +++++--- view/src/pages/auth/register.tsx | 16 ++++++++++++++-- 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 pkg/models/clients.go diff --git a/pkg/models/clients.go b/pkg/models/clients.go new file mode 100644 index 0000000..37bdfde --- /dev/null +++ b/pkg/models/clients.go @@ -0,0 +1,4 @@ +package models + +type OauthClients struct { +} diff --git a/view/src/layouts/RootLayout.tsx b/view/src/layouts/RootLayout.tsx index 0a5d582..0ae85bf 100644 --- a/view/src/layouts/RootLayout.tsx +++ b/view/src/layouts/RootLayout.tsx @@ -2,12 +2,24 @@ import Navbar from "./shared/Navbar.tsx"; import { readProfiles } from "../stores/userinfo.tsx"; import { createSignal, Show } from "solid-js"; import { readWellKnown } from "../stores/wellKnown.tsx"; +import { BeforeLeaveEventArgs, useBeforeLeave, useNavigate } from "@solidjs/router"; export default function RootLayout(props: any) { const [ready, setReady] = createSignal(false); Promise.all([readWellKnown(), readProfiles()]).then(() => setReady(true)); + const navigate = useNavigate() + + useBeforeLeave((e: BeforeLeaveEventArgs) => { + const whitelist = ["/auth/login", "/auth/register", "/users/me/confirm"] + + if (!whitelist.includes(e.to.toString()) && !e.defaultPrevented) { + e.preventDefault(); + navigate(`/auth/login?redirect_uri=${e.to.toString()}`) + } + }); + return ( diff --git a/view/src/pages/auth/login.tsx b/view/src/pages/auth/login.tsx index 699a956..0613367 100644 --- a/view/src/pages/auth/login.tsx +++ b/view/src/pages/auth/login.tsx @@ -1,5 +1,5 @@ import { readProfiles } from "../../stores/userinfo.tsx"; -import { useNavigate } from "@solidjs/router"; +import { useNavigate, useSearchParams } from "@solidjs/router"; import { createSignal, For, Match, Show, Switch } from "solid-js"; import Cookie from "universal-cookie"; @@ -15,6 +15,8 @@ export default function LoginPage() { const [challenge, setChallenge] = createSignal(); const [stage, setStage] = createSignal("starting"); + const[searchParams] = useSearchParams() + const navigate = useNavigate(); const handlers: { [id: string]: any } = { @@ -87,7 +89,7 @@ export default function LoginPage() { if (data["is_finished"]) { await grantToken(data["session"]["grant_token"]); await readProfiles(); - navigate("/"); + navigate(searchParams["redirect_uri"] ?? "/"); } else { setError(null); setStage("choosing"); @@ -211,7 +213,7 @@ export default function LoginPage() { diff --git a/view/src/pages/auth/register.tsx b/view/src/pages/auth/register.tsx index be5d2e4..30fce37 100644 --- a/view/src/pages/auth/register.tsx +++ b/view/src/pages/auth/register.tsx @@ -1,5 +1,6 @@ import { createSignal, Show } from "solid-js"; import { useWellKnown } from "../../stores/wellKnown.tsx"; +import { useNavigate, useSearchParams } from "@solidjs/router"; export default function RegisterPage() { const [title, setTitle] = createSignal("Create an account"); @@ -9,7 +10,10 @@ export default function RegisterPage() { const [loading, setLoading] = createSignal(false); const [done, setDone] = createSignal(false); + const [searchParams] = useSearchParams() + const metadata = useWellKnown(); + const navigate = useNavigate(); async function submit(evt: SubmitEvent) { evt.preventDefault(); @@ -34,6 +38,14 @@ export default function RegisterPage() { setLoading(false); } + function callback() { + if(searchParams["closable"]) { + window.close() + } else { + navigate("/auth/login") + } + } + return (
@@ -124,7 +136,7 @@ export default function RegisterPage() {

What's next?

- Go login{" "} + callback()} class="link">Go login{" "} then you can take part in the entire smartsheep community.
@@ -133,7 +145,7 @@ export default function RegisterPage() {