saM69420
saM69420
Explore posts from servers
KKinde
Created by saM69420 on 1/16/2024 in #💻┃support
Kinde + Bun + Hono + React
Thanks @leo_kinde I've updated the cookie options. It doesn't work with Strict, so I set it to Lax. I guess that's because of the way the callback redirect works upon successful sign in.
export const sessionManager = (c: Context): SessionManager => ({
async setSessionItem(key: string, value: unknown) {
const cookieOptions = {
httpOnly: true,
secure: true,
sameSite: "Lax",
} as const;
if (typeof value === "string") {
setCookie(c, key, value, cookieOptions);
} else {
setCookie(c, key, JSON.stringify(value), cookieOptions);
}
},
// ...
});
export const sessionManager = (c: Context): SessionManager => ({
async setSessionItem(key: string, value: unknown) {
const cookieOptions = {
httpOnly: true,
secure: true,
sameSite: "Lax",
} as const;
if (typeof value === "string") {
setCookie(c, key, value, cookieOptions);
} else {
setCookie(c, key, JSON.stringify(value), cookieOptions);
}
},
// ...
});
Then client side, my react app is using react query to grab the user details from the server and keeps them i'm memory for Infinity which works since logout and login require complete redirects anyway.
import api from "@/lib/api";
import { queryOptions } from "@tanstack/react-query";

async function authenticatedUser() {
const res = await api.me.$get();
if (!res.ok) {
throw new Error("Network response was not ok");
}
const data = await res.json();
return data.user;
}

export const userQueryOptions = queryOptions({
queryKey: ["user-me"],
queryFn: () => authenticatedUser(),
staleTime: Infinity,
});
import api from "@/lib/api";
import { queryOptions } from "@tanstack/react-query";

async function authenticatedUser() {
const res = await api.me.$get();
if (!res.ok) {
throw new Error("Network response was not ok");
}
const data = await res.json();
return data.user;
}

export const userQueryOptions = queryOptions({
queryKey: ["user-me"],
queryFn: () => authenticatedUser(),
staleTime: Infinity,
});
Then any component can get the user's details by performing the query that's already been cached.
import { Button } from "@/components/ui/button";

import { userQueryOptions } from "@/lib/user-query";
import { useQuery } from "@tanstack/react-query";

export default function ProfilePage() {

const {data: user} = useQuery(userQueryOptions);

return (
<div className="flex flex-col gap-y-4 items-center">
<h1 className="text-4xl font-bold">Hi {user?.given_name}</h1>
<div className="text-2xl font-bold">{user?.email}</div>
<Button asChild>
<a href="/logout">Logout</a>
</Button>
</div>
);
}
import { Button } from "@/components/ui/button";

import { userQueryOptions } from "@/lib/user-query";
import { useQuery } from "@tanstack/react-query";

export default function ProfilePage() {

const {data: user} = useQuery(userQueryOptions);

return (
<div className="flex flex-col gap-y-4 items-center">
<h1 className="text-4xl font-bold">Hi {user?.given_name}</h1>
<div className="text-2xl font-bold">{user?.email}</div>
<Button asChild>
<a href="/logout">Logout</a>
</Button>
</div>
);
}
So no extra context providers and no client side processing of the tokens. I would love any suggestions if there's room for improvement with any of this. Im trying to keep it as simple and robust as possible while only using the Kinde typescript SDK on the backend.
10 replies
KKinde
Created by saM69420 on 1/16/2024 in #💻┃support
Kinde + Bun + Hono + React
thank you 😊
10 replies
KKinde
Created by saM69420 on 1/16/2024 in #💻┃support
Kinde + Bun + Hono + React
bun is the typescript runtime instead of node.js hono is the backend framework instead of express
10 replies
KKinde
Created by saM69420 on 1/16/2024 in #💻┃support
Kinde + Bun + Hono + React
No issues, I just want to make sure i'm not shooting myself in the foot or causing any security issues. This is for a tutorial so I don't want to give people bad advice
10 replies
KKinde
Created by saM69420 on 11/27/2023 in #💻┃support
New Application Environments
For a moment I thought about setting up multiple next.js applications in the same environment to solve my problems
22 replies
KKinde
Created by saM69420 on 11/27/2023 in #💻┃support
New Application Environments
Thank you, mostly I wanted to make sure I'm doing things correctly or get advice on how to do things better if i'm not. The process I have made me feel like maybe I wasn't supposed to setup multiple environments.
22 replies
KKinde
Created by saM69420 on 11/27/2023 in #💻┃support
New Application Environments
The audience is student and jr devs, maybe intermediate. Sometimes I'm in a consulting position giving tech advice/teaching
22 replies
KKinde
Created by saM69420 on 11/27/2023 in #💻┃support
New Application Environments
College and YouTube. I'm an instructor and a YouTuber
22 replies
KKinde
Created by saM69420 on 11/27/2023 in #💻┃support
New Application Environments
It's working for me but it feels weird when i'm teaching other people how to use kinde. It's so easy to get to the production environment and a lot more clicks to get a dev environment setup
22 replies
KKinde
Created by saM69420 on 11/27/2023 in #💻┃support
New Application Environments
In the mean time, should I keep doing things the way I've been doing things?
22 replies
KKinde
Created by saM69420 on 11/27/2023 in #💻┃support
New Application Environments
Thank you
22 replies
KKinde
Created by saM69420 on 11/27/2023 in #💻┃support
New Application Environments
Perfect 👌
22 replies
KKinde
Created by saM69420 on 11/27/2023 in #💻┃support
New Application Environments
When i'm testing locally, I'm going to need local API keys and localhost urls for callbacks in kinde and for the social providers. I'm assuming that creating a new environment would be the correct way of doing this, but maybe i'm wrong With clerk for example, I get a development environment, then when I'm happy with everything, I copy it to a production environment
22 replies
KKinde
Created by saM69420 on 11/27/2023 in #💻┃support
New Application Environments
Different user base for each application (project) When I made a new environment, I expected it to copy the other environment, so just a next app would exist.
22 replies
KKinde
Created by saM69420 on 11/27/2023 in #💻┃support
New Application Environments
Any type of web application that needs user auth and management and each application would be separate from each other. Imagine I have a bunch of side projects or startup ideas and I'm using kinde for each of them. What should I do when I'm making a new app.
22 replies
KKinde
Created by saM69420 on 11/16/2023 in #💻┃support
Customize Registration Fields
thank you
6 replies
DTDrizzle Team
Created by saM69420 on 10/5/2023 in #help
Creating a Case-Insensitive Unique Index
I can create a blank migration and add the constraint myself
drizzle-kit generate:pg --custom
drizzle-kit generate:pg --custom
CREATE UNIQUE INDEX users_username_unique ON public.users USING btree (LOWER(username)) NULLS NOT DISTINCT;
CREATE UNIQUE INDEX users_username_unique ON public.users USING btree (LOWER(username)) NULLS NOT DISTINCT;
It works exactly as I expect: "sam", "Sam", and "saM" all have the same index. I can add this constraint in drizzle, but drizzle-kit ignores where and using:
export const users = pgTable("users", {
username: varchar("username", { length: 30 }).notNull(),
//...
}, (table) => {
return {
usernameIdx: uniqueIndex("username_unique_idx").on(table.username).using(sql`btree (LOWER(username))`).where(sql` NULLS NOT DISTINCT`),
};
});
export const users = pgTable("users", {
username: varchar("username", { length: 30 }).notNull(),
//...
}, (table) => {
return {
usernameIdx: uniqueIndex("username_unique_idx").on(table.username).using(sql`btree (LOWER(username))`).where(sql` NULLS NOT DISTINCT`),
};
});
So that only makes a normal unique constraint. I'm curious to know if my approach of creating a case-insensitive unique Index is a good one. And if this is, or will be, possible using drizzle. I honestly don't mind making custom migrations for cases like this and adding check constraints -- but when my dev flow involves prototyping and pushing...
8 replies
DTDrizzle Team
Created by Jökull Sólberg on 5/25/2023 in #help
Simulate enums with SQLite `CHECK()`
sqlite has an enum option on the text type that does everything except adding the CHECK constraint. it's in the old docs just not the new ones https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/sqlite-core/README.md#column-types but no runtime checks, but it plays nice with drizzle-zod
12 replies