chore: format document
This commit is contained in:
parent
e763caf389
commit
aed9742a4d
@ -1,7 +1,7 @@
|
|||||||
import { User } from "@/lib/types"
|
import { User } from "@/lib/types"
|
||||||
|
import { generateUniqueUsername } from "@/lib/username-generator"
|
||||||
import { currentUser } from "@clerk/nextjs"
|
import { currentUser } from "@clerk/nextjs"
|
||||||
import { redirect } from "next/navigation"
|
import { redirect } from "next/navigation"
|
||||||
import { generateUniqueUsername } from "@/lib/username-generator";
|
|
||||||
|
|
||||||
export default async function AppAuthLayout({
|
export default async function AppAuthLayout({
|
||||||
children,
|
children,
|
||||||
@ -27,22 +27,24 @@ export default async function AppAuthLayout({
|
|||||||
if (!dbUserJSON.id) {
|
if (!dbUserJSON.id) {
|
||||||
// Try to get GitHub username if available
|
// Try to get GitHub username if available
|
||||||
const githubUsername = user.externalAccounts.find(
|
const githubUsername = user.externalAccounts.find(
|
||||||
account => account.provider === "github"
|
(account) => account.provider === "github"
|
||||||
)?.username;
|
)?.username
|
||||||
|
|
||||||
const username = githubUsername || await generateUniqueUsername(async (username) => {
|
const username =
|
||||||
// Check if username exists in database
|
githubUsername ||
|
||||||
const userCheck = await fetch(
|
(await generateUniqueUsername(async (username) => {
|
||||||
`${process.env.NEXT_PUBLIC_DATABASE_WORKER_URL}/api/user/check-username?username=${username}`,
|
// Check if username exists in database
|
||||||
{
|
const userCheck = await fetch(
|
||||||
headers: {
|
`${process.env.NEXT_PUBLIC_DATABASE_WORKER_URL}/api/user/check-username?username=${username}`,
|
||||||
Authorization: `${process.env.NEXT_PUBLIC_WORKERS_KEY}`,
|
{
|
||||||
},
|
headers: {
|
||||||
}
|
Authorization: `${process.env.NEXT_PUBLIC_WORKERS_KEY}`,
|
||||||
)
|
},
|
||||||
const exists = await userCheck.json()
|
}
|
||||||
return exists.exists
|
)
|
||||||
});
|
const exists = await userCheck.json()
|
||||||
|
return exists.exists
|
||||||
|
}))
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_DATABASE_WORKER_URL}/api/user`,
|
`${process.env.NEXT_PUBLIC_DATABASE_WORKER_URL}/api/user`,
|
||||||
@ -64,11 +66,11 @@ export default async function AppAuthLayout({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const error = await res.text();
|
const error = await res.text()
|
||||||
console.error("Failed to create user:", error);
|
console.error("Failed to create user:", error)
|
||||||
} else {
|
} else {
|
||||||
const data = await res.json();
|
const data = await res.json()
|
||||||
console.log("User created successfully:", data);
|
console.log("User created successfully:", data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user