* feat: replace manual oauth with better-auth * fix: lint * chore: refactor accounts to unify github + vercel * feat: enhance auth config with host allowlisting Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * fix: add newline at end of manifest.json Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * fix: update betterAuth database schema mappings Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * fix: sanitize redirects and preserve destination in github flow Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * feat: enhance GitHub app callback with installation sync tracking Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * build: add BETTER_AUTH_SECRET to turbo env Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * refactor: update sign-in callback to skip onboarding Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> --------- Co-authored-by: nicoalbanese <49612682+nicoalbanese@users.noreply.github.com> Co-authored-by: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com>
38 lines
906 B
TypeScript
38 lines
906 B
TypeScript
import type { NextRequest } from "next/server";
|
|
import type { Session } from "./types";
|
|
import { auth } from "@/lib/auth/config";
|
|
|
|
function extractUsername(user: {
|
|
name?: string | null;
|
|
[key: string]: unknown;
|
|
}): string {
|
|
if (typeof user.username === "string" && user.username) {
|
|
return user.username;
|
|
}
|
|
return user.name ?? "";
|
|
}
|
|
|
|
export async function getSessionFromReq(
|
|
req: NextRequest,
|
|
): Promise<Session | undefined> {
|
|
const baSession = await auth.api.getSession({
|
|
headers: req.headers,
|
|
});
|
|
|
|
if (!baSession?.user) {
|
|
return undefined;
|
|
}
|
|
|
|
return {
|
|
created: baSession.session.createdAt.getTime(),
|
|
authProvider: "vercel",
|
|
user: {
|
|
id: baSession.user.id,
|
|
username: extractUsername(baSession.user),
|
|
email: baSession.user.email ?? undefined,
|
|
avatar: baSession.user.image ?? "",
|
|
name: baSession.user.name ?? undefined,
|
|
},
|
|
};
|
|
}
|