Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Sign out function + improved login notification flow

Richie McIlroy9155b83e5b16
diff --git a/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx b/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx
index 3d25ae093..8b46896ff 100644
--- a/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx
+++ b/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx
@@ -6,15 +6,14 @@ import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
- DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
- Button,
} from "@cap/ui";
import { UsageButton } from "@/components/UsageButton";
import { users, spaces } from "@cap/database/schema";
import Link from "next/link";
import { isUserOnProPlan } from "@cap/utils";
+import { signOut } from "next-auth/react";
type SharedContext = {
spaceData: (typeof spaces.$inferSelect)[] | null;
@@ -119,9 +118,9 @@ export default function DynamicSharedLayout({
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem>
- <Link className="w-full" href="/logout">
+ <button className="w-full" onClick={() => signOut()}>
Sign out
- </Link>
+ </button>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
diff --git a/apps/web/app/login/form.tsx b/apps/web/app/login/form.tsx
index 90e8c8b74..c78c551ac 100644
--- a/apps/web/app/login/form.tsx
+++ b/apps/web/app/login/form.tsx
@@ -11,6 +11,7 @@ export function LoginForm() {
const next = searchParams?.get("next");
const [email, setEmail] = useState("");
const [loading, setLoading] = useState(false);
+ const [emailSent, setEmailSent] = useState(false);
useEffect(() => {
const error = searchParams?.get("error");
@@ -31,21 +32,17 @@ export function LoginForm() {
...(next && next.length > 0 ? { callbackUrl: next } : {}),
})
.then((res) => {
- console.log("res");
- console.log(res);
setLoading(false);
if (res?.ok && !res?.error) {
setEmail("");
- toast.success("Email sent - check your inbox!", {
- duration: 20000,
- });
+ setEmailSent(true);
+ toast.success("Email sent - check your inbox!");
} else {
toast.error("Error sending email - try again?");
}
})
.catch((err) => {
- console.log("err");
- console.log(err);
+ setEmailSent(false);
setLoading(false);
toast.error("Error sending email - try again?");
});
@@ -58,10 +55,11 @@ export function LoginForm() {
name="email"
autoFocus
type="email"
- placeholder="[email protected]"
+ placeholder={emailSent ? "" : "[email protected]"}
autoComplete="email"
required
value={email}
+ disabled={emailSent}
onChange={(e) => {
setEmail(e.target.value);
}}
@@ -73,9 +71,9 @@ export function LoginForm() {
size="lg"
className="h-12 text-lg"
type="submit"
- disabled={loading}
+ disabled={loading || emailSent}
>
- Continue with Email
+ {emailSent ? "Email was sent to your inbox" : "Continue with Email"}
</Button>
<p className="text-xs text-gray-500 pt-2">
By typing your email and clicking continue, you acknowledge that you
@@ -98,6 +96,20 @@ export function LoginForm() {
.
</p>
</form>
+ {emailSent && (
+ <div>
+ <button
+ className="mt-5 text-sm text-gray-500 underline hover:text-black"
+ onClick={() => {
+ setEmailSent(false);
+ setEmail("");
+ setLoading(false);
+ }}
+ >
+ Click to restart sign in process.
+ </button>
+ </div>
+ )}
</>
);
}