Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

wip: Desktop app auth

Richie McIlroye3318b7997f9
diff --git a/apps/desktop/next.config.mjs b/apps/desktop/next.config.mjs
index 55e957c25..f24a426d6 100644
--- a/apps/desktop/next.config.mjs
+++ b/apps/desktop/next.config.mjs
@@ -1,11 +1,8 @@
-import million from "million/compiler";
-
/** @type {import('next').NextConfig} */
import("dotenv").then(({ config }) => config({ path: "../../.env" }));
const nextConfig = {
- output: "export",
reactStrictMode: true,
swcMinify: true,
transpilePackages: ["@cap/ui", "@cap/utils"],
@@ -20,10 +17,4 @@ const nextConfig = {
},
};
-const millionConfig = {
- auto: {
- rsc: true,
- },
-};
-
-export default million.next(nextConfig, millionConfig);
+export default nextConfig;
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 7ae2e8211..c815021e6 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -19,6 +19,7 @@
"million": "^2.6.4",
"next": "^14.1.0",
"postcss": "^8.4.31",
+ "next-auth": "^4.24.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hot-toast": "^2.4.1",
diff --git a/apps/desktop/src-tauri/tauri.conf.json b/apps/desktop/src-tauri/tauri.conf.json
index f35170080..39dfc06cb 100644
--- a/apps/desktop/src-tauri/tauri.conf.json
+++ b/apps/desktop/src-tauri/tauri.conf.json
@@ -3,7 +3,7 @@
"beforeDevCommand": "next dev -p 3001",
"beforeBuildCommand": "next build",
"devPath": "http://localhost:3001",
- "distDir": "../out",
+ "distDir": "../.next",
"withGlobalTauri": false
},
"package": {
diff --git a/apps/desktop/src/app/api/auth/[...nextauth]/route.ts b/apps/desktop/src/app/api/auth/[...nextauth]/route.ts
new file mode 100644
index 000000000..565ccb6cb
--- /dev/null
+++ b/apps/desktop/src/app/api/auth/[...nextauth]/route.ts
@@ -0,0 +1,6 @@
+import NextAuth from "next-auth";
+import { authOptions } from "@cap/database/auth/auth-options";
+
+const handler = NextAuth(authOptions);
+
+export { handler as GET, handler as POST };
diff --git a/apps/desktop/src/app/layout.tsx b/apps/desktop/src/app/layout.tsx
index 19568c8a9..ef5428076 100644
--- a/apps/desktop/src/app/layout.tsx
+++ b/apps/desktop/src/app/layout.tsx
@@ -1,5 +1,6 @@
"use client";
-import "@/app/styles.css";
+import "./styles.css";
+import { MediaDeviceProvider } from "@/utils/recording/MediaDeviceContext";
import { Toaster } from "react-hot-toast";
export default async function RootLayout({
@@ -42,7 +43,9 @@ export default async function RootLayout({
</head>
<body>
<Toaster />
- <main className="w-full overflow-hidden">{children}</main>
+ <main className="w-full overflow-hidden">
+ <MediaDeviceProvider>{children}</MediaDeviceProvider>
+ </main>
</body>
</html>
);
diff --git a/apps/desktop/src/app/options/page.tsx b/apps/desktop/src/app/options/page.tsx
index 998ae52c5..acd1b2470 100644
--- a/apps/desktop/src/app/options/page.tsx
+++ b/apps/desktop/src/app/options/page.tsx
@@ -1,7 +1,14 @@
-"use client";
-
-import { Options } from "@/components/windows/Options";
+"use server";
+// import { SignIn } from "@/components/windows/inner/SignIn";
+import { Recorder } from "@/components/windows/inner/Recorder";
+import { getCurrentUser } from "@cap/database/auth/session";
export default async function CameraPage() {
- return <Options />;
+ const session = await getCurrentUser();
+
+ if (!session) {
+ return <Recorder />;
+ }
+
+ return <Recorder />;
}
diff --git a/apps/desktop/src/app/page.tsx b/apps/desktop/src/app/page.tsx
new file mode 100644
index 000000000..8e5f1fb22
--- /dev/null
+++ b/apps/desktop/src/app/page.tsx
@@ -0,0 +1,7 @@
+"use server";
+
+import { redirect } from "next/navigation";
+
+export default async function IndexPage() {
+ redirect("/options");
+}
diff --git a/apps/desktop/src/components/Button.tsx b/apps/desktop/src/components/Button.tsx
index 973151695..52672dfa7 100644
--- a/apps/desktop/src/components/Button.tsx
+++ b/apps/desktop/src/components/Button.tsx
@@ -1,3 +1,5 @@
+"use client";
+
export const Button = ({
variant,
handler,
diff --git a/apps/desktop/src/components/windows/inner/Countdown.tsx b/apps/desktop/src/components/windows/inner/Countdown.tsx
index f30cabfed..7d60ff50f 100644
--- a/apps/desktop/src/components/windows/inner/Countdown.tsx
+++ b/apps/desktop/src/components/windows/inner/Countdown.tsx
@@ -1,3 +1,5 @@
+"use client";
+
import { useEffect, useState } from "react";
interface CountdownOverlayProps {
diff --git a/apps/desktop/src/components/windows/inner/Recorder.tsx b/apps/desktop/src/components/windows/inner/Recorder.tsx
index 97eb89aca..910e9064e 100644
--- a/apps/desktop/src/components/windows/inner/Recorder.tsx
+++ b/apps/desktop/src/components/windows/inner/Recorder.tsx
@@ -1,3 +1,5 @@
+"use client";
+
import { useState, useEffect } from "react";
import { useMediaDevices } from "@/utils/recording/MediaDeviceContext";
import { Video } from "@/components/icons/Video";
@@ -25,7 +27,7 @@ import { uuidParse } from "@cap/utils";
import toast, { Toaster } from "react-hot-toast";
import { LogicalSize, WebviewWindow, appWindow } from "@tauri-apps/api/window";
-export const Recorder = ({ session }: { session: null }) => {
+export const Recorder = () => {
const {
devices,
selectedVideoDevice,
@@ -175,7 +177,7 @@ export const Recorder = ({ session }: { session: null }) => {
console.log("Opening window...");
await openLinkInBrowser(
- `${import.meta.env.VITE_PUBLIC_URL}/share/${uuidParse(
+ `${process.env.NEXT_PUBLIC_URL}/share/${uuidParse(
await getLatestVideoId()
)}`
);
@@ -253,7 +255,7 @@ export const Recorder = ({ session }: { session: null }) => {
</div>
<div>
<label className="text-sm font-medium">Webcam / Video</label>
- <div className="space-y-1">
+ <div>
<ActionButton
width="full"
handler={() => handleContextClick("video")}
diff --git a/apps/desktop/src/components/windows/inner/SignIn.tsx b/apps/desktop/src/components/windows/inner/SignIn.tsx
index dbf15589d..64cf18a36 100644
--- a/apps/desktop/src/components/windows/inner/SignIn.tsx
+++ b/apps/desktop/src/components/windows/inner/SignIn.tsx
@@ -1,50 +1,21 @@
-import { useState } from "react";
-// import { supabase } from "@/utils/database/client";
-import { Button } from "@/components/Button";
-import { Logo } from "@/components/icons/Logo";
-// import toast from "react-hot-toast";
+"use client";
-//TODO: Auth
+import { Button, Logo } from "@cap/ui";
+import { signIn } from "next-auth/react";
+import { useSearchParams } from "next/navigation";
+import { useEffect, useState } from "react";
+import { toast } from "react-hot-toast";
export const SignIn = () => {
- const [email, setEmail] = useState<string>("");
- const [OTPcode, setOTPcode] = useState<string>("");
- const [enterCode, setEnterCode] = useState(false);
+ const searchParams = useSearchParams();
+ const next = searchParams?.get("next");
+ const [email, setEmail] = useState("");
+ const [loading, setLoading] = useState(false);
- // const handleLogin = async () => {
- // const { error } = await supabase.auth.signInWithOtp({
- // email: email,
- // });
-
- // if (error) {
- // toast.error(`Error: ${error.message}`);
- // console.log({ error });
- // return;
- // }
-
- // setEnterCode(true);
- // };
-
- // const verifyOTPCode = async () => {
- // if (!email || !OTPcode) {
- // toast.error(`Error: Email or OTP code is missing`);
- // return;
- // }
-
- // console.log({ email, OTPcode });
-
- // const { error } = await supabase.auth.verifyOtp({
- // email: email,
- // token: OTPcode,
- // type: "magiclink",
- // });
-
- // if (error) {
- // toast.error(`Error: ${error.message}`);
- // console.log({ error });
- // return;
- // }
- // };
+ useEffect(() => {
+ const error = searchParams?.get("error");
+ error && toast.error(error);
+ }, [searchParams]);
return (
<div className="w-[85%] h-[85%] flex items-center justify-center overflow-hidden px-2 py-4 rounded-[25px] border-2 border-gray-100 bg-gradient-to-b from-gray-200 to-white flex flex-col items-center justify-center">
@@ -52,54 +23,57 @@ export const SignIn = () => {
<div className="mb-12">
<Logo className="w-32 h-auto mx-auto" />
</div>
- <div className="max-w-sm mx-auto flex items-center relative h-14 mb-8">
- <input
- onChange={(e) => {
- enterCode ? setOTPcode(e.target.value) : setEmail(e.target.value);
- }}
- type={enterCode ? "number" : "email"}
- placeholder={enterCode ? "Enter code" : "Your email"}
- required
- value={enterCode ? OTPcode : email}
- className="text-sm w-full bg-gray-300 rounded-full py-2 px-5 mt-3 outline-none focus-none text-black placeholder:text-gray-600 h-full"
- />
- {enterCode === false ? (
- <div className="mt-3 text-center absolute right-0 h-full">
- <Button
- handler={() => {}}
- variant="primary"
- label="Continue"
- className="h-full rounded-tr-full rounded-br-full min-w-[100px] border-none"
- />
- </div>
- ) : (
- <div className="mt-3 text-center absolute right-0 h-full">
- <Button
- handler={() => {}}
- variant="primary"
- label="Confirm"
- className="h-full rounded-tr-full rounded-br-full min-w-[100px] border-none"
- />
- </div>
- )}
- </div>
- <div className="text-center">
- <button
- type="button"
- className="underline text-sm"
- onClick={() => {
- if (enterCode) {
- setEmail("");
- setEnterCode(false);
- } else {
- setOTPcode("");
- setEnterCode(true);
- }
- }}
- >
- {enterCode ? "Don't have a code?" : "Already have a code?"}
- </button>
- </div>
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+ if (!email) return;
+
+ setLoading(true);
+ signIn("email", {
+ email,
+ redirect: false,
+ ...(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!");
+ } else {
+ toast.error("Error sending email - try again?");
+ }
+ })
+ .catch((err) => {
+ console.log("err");
+ console.log(err);
+ setLoading(false);
+ toast.error("Error sending email - try again?");
+ });
+ }}
+ className="flex flex-col space-y-3"
+ >
+ <div>
+ <input
+ id="email"
+ name="email"
+ autoFocus
+ type="email"
+ placeholder="[email protected]"
+ autoComplete="email"
+ required
+ value={email}
+ onChange={(e) => {
+ setEmail(e.target.value);
+ }}
+ className="mt-1 block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm"
+ />
+ </div>
+ <Button variant="default" type="submit" disabled={loading}>
+ Continue with Email
+ </Button>
+ </form>
</div>
</div>
);
diff --git a/apps/desktop/src/utils/recording/MediaDeviceContext.tsx b/apps/desktop/src/utils/recording/MediaDeviceContext.tsx
index 2768a754f..6b3420053 100644
--- a/apps/desktop/src/utils/recording/MediaDeviceContext.tsx
+++ b/apps/desktop/src/utils/recording/MediaDeviceContext.tsx
@@ -1,3 +1,5 @@
+"use client";
+
import {
useState,
createContext,
diff --git a/apps/web/app/api/auth/[...nextauth]/route.ts b/apps/web/app/api/auth/[...nextauth]/route.ts
index 5260070c9..565ccb6cb 100644
--- a/apps/web/app/api/auth/[...nextauth]/route.ts
+++ b/apps/web/app/api/auth/[...nextauth]/route.ts
@@ -3,6 +3,4 @@ import { authOptions } from "@cap/database/auth/auth-options";
const handler = NextAuth(authOptions);
-console.log("handler", handler);
-
export { handler as GET, handler as POST };
diff --git a/packages/ui/style/tailwind.config.js b/packages/ui/style/tailwind.config.js
index 87e427749..16b91e89b 100644
--- a/packages/ui/style/tailwind.config.js
+++ b/packages/ui/style/tailwind.config.js
@@ -4,6 +4,7 @@ module.exports = function (app, options) {
`../../apps/${app}/pages/**/*.{js,ts,jsx,tsx,mdx}`,
`../../apps/${app}/components/**/*.{js,ts,jsx,tsx,mdx}`,
`../../apps/${app}/app/**/*.{js,ts,jsx,tsx,mdx}`,
+ `../../apps/${app}/src/**/*.{js,ts,jsx,tsx,mdx}`,
"../../packages/*/src/**/*.{ts,tsx,html,stories.tsx}",
],
theme: {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 0cc85d2b2..e2f34f55b 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -53,6 +53,9 @@ importers:
next:
specifier: ^14.1.0
+ next-auth:
+ specifier: ^4.24.5
postcss:
specifier: ^8.4.31
version: 8.4.33