KHRM
KHRM
Explore posts from servers
KKinde
Created by conkyyy on 10/3/2024 in #💻┃support
How to add subdomain auth flow for a multi tenant app?
No description
6 replies
KKinde
Created by conkyyy on 10/3/2024 in #💻┃support
How to add subdomain auth flow for a multi tenant app?
currently not using kinde middleware since i just set it up (also not sure if that is a facto)
6 replies
KKinde
Created by conkyyy on 10/3/2024 in #💻┃support
How to add subdomain auth flow for a multi tenant app?
hoping I can hop on this old thread because im trying to do something similar here is my .env
.env
KINDE_CLIENT_ID=...
KINDE_CLIENT_SECRET=...
KINDE_ISSUER_URL=https://nextboards.kinde.com
KINDE_SITE_URL=http://localhost:3000
KINDE_POST_LOGOUT_REDIRECT_URL=http://localhost:3000
KINDE_POST_LOGIN_REDIRECT_URL=http://localhost:3000
.env
KINDE_CLIENT_ID=...
KINDE_CLIENT_SECRET=...
KINDE_ISSUER_URL=https://nextboards.kinde.com
KINDE_SITE_URL=http://localhost:3000
KINDE_POST_LOGOUT_REDIRECT_URL=http://localhost:3000
KINDE_POST_LOGIN_REDIRECT_URL=http://localhost:3000
I want the user to be able to login from http://localhost:3000 or http://*.localhost:3000 (i.e. http://testing.localhost:3000, http://potato.localhost:3000) and have the same user I log in from http://localhost:3000 and i see my user but when i go to http://testing.localhost:3000 the user is null (also there are no cookies so that makes sense) not sure how to use the wildcard strategy here im usingNext.js v15 app router currently I am using nextjs rewrites to access my subdomain not sure if that is related to the issue
import { NextRequest, NextResponse } from 'next/server'

const ROOT_DOMAIN = process.env.NEXT_PUBLIC_ROOT_DOMAIN

if (!ROOT_DOMAIN) {
throw new Error('NEXT_PUBLIC_ROOT_DOMAIN is not set')
}

export default async function middleware(req: NextRequest) {
const nextUrl = req.nextUrl
let hostname = req.headers.get('host')!

hostname = hostname.replace(`.${ROOT_DOMAIN}`, '')

const searchParams = req.nextUrl.searchParams.toString()
const path = `${nextUrl.pathname}${searchParams ? `?${searchParams}` : ''}`

if (!hostname || hostname === ROOT_DOMAIN) return NextResponse.next()

const session = true
if (!session && path !== '/login') {
return NextResponse.redirect(new URL('/login', req.url))
} else if (session && path === '/login') {
return NextResponse.redirect(new URL('/', req.url))
}

return NextResponse.rewrite(new URL(`/site/${hostname}${path}`, nextUrl.href))
}

export const config = {
matcher: [
'/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)',
],
}
import { NextRequest, NextResponse } from 'next/server'

const ROOT_DOMAIN = process.env.NEXT_PUBLIC_ROOT_DOMAIN

if (!ROOT_DOMAIN) {
throw new Error('NEXT_PUBLIC_ROOT_DOMAIN is not set')
}

export default async function middleware(req: NextRequest) {
const nextUrl = req.nextUrl
let hostname = req.headers.get('host')!

hostname = hostname.replace(`.${ROOT_DOMAIN}`, '')

const searchParams = req.nextUrl.searchParams.toString()
const path = `${nextUrl.pathname}${searchParams ? `?${searchParams}` : ''}`

if (!hostname || hostname === ROOT_DOMAIN) return NextResponse.next()

const session = true
if (!session && path !== '/login') {
return NextResponse.redirect(new URL('/login', req.url))
} else if (session && path === '/login') {
return NextResponse.redirect(new URL('/', req.url))
}

return NextResponse.rewrite(new URL(`/site/${hostname}${path}`, nextUrl.href))
}

export const config = {
matcher: [
'/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)',
],
}
6 replies
PPrisma
Created by kimb0x on 11/5/2024 in #help-and-questions
Can't delete records from Prisma Postgres in Studio
I had this issue too, one of my tables didn't have an @id only an @unique and it seems to work after I made the schema change and made it an @id Not sure if that's the actual issue
27 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
I read some where recently you can write mysql functions in JavaScript now so thats pretty cool
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
true sometimes wonder if that would be more ideal than doing it at the server level
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
couldnt figure out a good solution so I opted for having an earliestDate flag
const initialEvents = await db.event.findMany({
include: {
eventDates: {
orderBy: { date: "asc" },
},
},
orderBy: { earliestDate: "asc" },
take: TAKE_EVENTS_LIMIT,
});
const initialEvents = await db.event.findMany({
include: {
eventDates: {
orderBy: { date: "asc" },
},
},
orderBy: { earliestDate: "asc" },
take: TAKE_EVENTS_LIMIT,
});
I just have to now make sure that whenever an eventDate is delete I keep it in sync i.e. make sure earliestDate is updated for the event if needed
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
I do have access to postgres but here I am trying to expand xD wanted to try out Turso
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
I tried the typed SQL was pretty damn cool I might made a video on it But with sqlite it's gonna be hard to aggregate eegate the dates without turning them into strings
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
Yeah it doesn't allow it
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
newer models
model TempEvent {
eventId String @id @default(cuid()) @map("event_id")
title String

eventDates TempEventDate[]

@@map("temp_events")
}

model TempEventDate {
dateId Int @id @default(autoincrement()) @map("date_id")

date DateTime

event TempEvent @relation(fields: [eventId], references: [eventId])
eventId String @map("event_id")

@@map("temp_event_dates")
}
model TempEvent {
eventId String @id @default(cuid()) @map("event_id")
title String

eventDates TempEventDate[]

@@map("temp_events")
}

model TempEventDate {
dateId Int @id @default(autoincrement()) @map("date_id")

date DateTime

event TempEvent @relation(fields: [eventId], references: [eventId])
eventId String @map("event_id")

@@map("temp_event_dates")
}
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
No description
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
I just reduced it from 3 tables to two tables xD but prisma still doesn't let you sort by relations just count for some reason
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
yeah I might refactor to something like that, will look more into that jsonb thing as well It'll also make the queries overall simpler Thanks for the tips felt nice to talk about code with someone been a lonely journey haha
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
Well give or take the years, events would usually be within a year or so in practice and then they'd be deleted as needed
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
But I don't know if that has any real benefit
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
there's only 365 dates in a year so this way only 365 rows would be the max for the dates table
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
it's more like I want to practice the real purpose of all 3 tables was to reuse dates but honestly I don't think it's worth it Should just have 2 or even 1 table for this type of thing and just aggregate on the dates
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
thanks I'll check it out for learning purposes But it might be easier in my case to add a field to my events table called earliestDate
38 replies
PPrisma
Created by KHRM on 10/3/2024 in #help-and-questions
Sorting by Relations
view sounds interesting I think I'd like to explore any pointers on how to get started on that
38 replies