Skip to content

Commit 49f91bb

Browse files
committed
update Discord authentication logic to use new utility functions and improve ID generation
1 parent e75c754 commit 49f91bb

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/app/(auth)/login/discord/callback/route.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { discord } from "@/lib/auth";
2-
import utils from "@/lib/auth/utils";
1+
import { discord } from "@/lib/auth/config";
2+
import { createSession, setCookie } from "@/lib/auth/utils";
33
import { Paths } from "@/lib/constants";
44
import { db } from "@/server/db";
55
import { users } from "@/server/db/schema";
66
import { OAuth2RequestError } from "arctic";
77
import { eq } from "drizzle-orm";
8+
import { nanoid } from "nanoid";
89
import { cookies } from "next/headers";
910

1011
export async function GET(request: Request): Promise<Response> {
@@ -49,16 +50,16 @@ export async function GET(request: Request): Promise<Response> {
4950
: null;
5051

5152
if (!existingUser) {
52-
const userId = utils.generateId(21);
53+
const userId = nanoid(21);
5354
await db.insert(users).values({
5455
id: userId,
5556
email: discordUser.email,
5657
emailVerified: true,
5758
discordId: discordUser.id,
5859
avatar,
5960
});
60-
const session = await utils.createSession(userId);
61-
await utils.setCookie(session.id);
61+
const session = await createSession(userId);
62+
await setCookie(session.id);
6263
return new Response(null, {
6364
status: 302,
6465
headers: { Location: Paths.Dashboard },
@@ -75,8 +76,8 @@ export async function GET(request: Request): Promise<Response> {
7576
})
7677
.where(eq(users.id, existingUser.id));
7778
}
78-
const session = await utils.createSession(existingUser.id);
79-
await utils.setCookie(session.id);
79+
const session = await createSession(existingUser.id);
80+
await setCookie(session.id);
8081

8182
return new Response(null, {
8283
status: 302,

src/app/(auth)/login/discord/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { env } from "@/env";
2-
import { discord } from "@/lib/auth";
2+
import { discord } from "@/lib/auth/config";
33
import { generateState } from "arctic";
44
import { cookies } from "next/headers";
55

0 commit comments

Comments
 (0)