diff --git a/.env.sample b/.env.sample index ed183a1..2a81e1c 100644 --- a/.env.sample +++ b/.env.sample @@ -2,8 +2,8 @@ NEXT_PUBLIC_ZERO_SERVER='http://localhost:4848' ZERO_UPSTREAM_DB="postgresql://user:password@127.0.0.1:5432/zstart" ZERO_CVR_DB="postgresql://user:password@127.0.0.1:5432/zstart_cvr" ZERO_CHANGE_DB="postgresql://user:password@127.0.0.1:5432/zstart_cdb" -ZERO_AUTH_SECRET="secretkey" ZERO_REPLICA_FILE="/tmp/zstart_replica.db" +ZERO_AUTH_JWKS_URL="http://localhost:3000/api/auth/jwks" AUTH_SECRET="" # Added by `npx auth`. Read more: https://cli.authjs.dev @@ -12,3 +12,6 @@ AUTH_DRIZZLE_URL=$ZERO_UPSTREAM_DB AUTH_STRAVA_ID= AUTH_STRAVA_SECRET= AUTH_STRAVA_REDIRECT_URL="http://localhost:3000" + +BETTER_AUTH_SECRET= +BETTER_AUTH_URL="http://localhost:3000" \ No newline at end of file diff --git a/app/(app)/layout.tsx b/app/(app)/layout.tsx index 2a05745..af455e0 100644 --- a/app/(app)/layout.tsx +++ b/app/(app)/layout.tsx @@ -23,9 +23,7 @@ export default async function Layout({
Loading...}> - - {children} - + {children} ); diff --git a/app/actions.ts b/app/actions.ts deleted file mode 100644 index b7cae25..0000000 --- a/app/actions.ts +++ /dev/null @@ -1,65 +0,0 @@ -"use server"; - -// import { eq } from "drizzle-orm"; -import * as jose from "jose"; - -// import { redirect } from "next/navigation"; -// import { db } from "@/db"; -// import { users as usersTable } from "@/db/schema"; - -const secret = new TextEncoder().encode(process.env.ZERO_AUTH_SECRET!); -const alg = "HS256" as const; - -// export async function signIn(formData: FormData) { -// // Get the request data -// const email = formData.get("email") as string | null; -// const password = formData.get("password") as string | null; -// if (!email || !password) { -// throw new Error("username and/or email not set"); -// } -// console.log("email", email, "password", password); - -// // Query the database -// const results = await db -// .select() -// .from(usersTable) -// .where(eq(usersTable.email, email)); - -// const user = results[0]; -// if (!user) { -// throw new Error("email doesn't exist"); -// } -// console.log("user", user); - -// // Do the passwords match? -// if (!(await bcrypt.compare(password, user.passHash))) { -// throw new Error("passwords don't match"); -// } -// console.log("passwords match"); - -// // Create a JWT -// const jwt = await new jose.SignJWT({ sub: user.id }) -// .setProtectedHeader({ alg }) -// .setIssuedAt() -// .setExpirationTime("1h") -// .sign(secret); - -// // Set the cookie - -// // Done! -// redirect("/users"); -// } - -export const getNewToken = async (userId: string) => { - // Create a JWT - const jwt = await new jose.SignJWT({ sub: userId }) - .setProtectedHeader({ alg }) - .setIssuedAt() - .setExpirationTime("1h") - .sign(secret); - - // CAN ONLY SET COOKIE IN Server Action or Route Handler - // cookieStore.set("token", jwt); - - return jwt; -}; diff --git a/components/single-user.tsx b/components/single-user.tsx index f840b68..fc43954 100644 --- a/components/single-user.tsx +++ b/components/single-user.tsx @@ -15,11 +15,15 @@ export const User = ({ id }: { id: string }) => { const { value } = e.target; z.mutate.user.update({ - id: user.id, + id: user?.id, name: value, }); }; + if (!user) { + return
Loading
; + } + return (
diff --git a/components/user-list.tsx b/components/user-list.tsx index 420e95d..a1bcff1 100644 --- a/components/user-list.tsx +++ b/components/user-list.tsx @@ -13,7 +13,7 @@ export function UserList() { {users.length > 0 ? (