Skip to content

Commit 5cd5e0c

Browse files
committed
reformat files
1 parent 0bbfd59 commit 5cd5e0c

File tree

2 files changed

+148
-148
lines changed

2 files changed

+148
-148
lines changed

dev-auth/oidc-provider.mjs

Lines changed: 108 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -5,131 +5,131 @@ const PORT = 4000;
55

66
// Simple in-memory account storage
77
const accounts = {
8-
"test-user": {
9-
accountId: "test-user",
10-
11-
email_verified: true,
12-
name: "Test User",
13-
},
8+
"test-user": {
9+
accountId: "test-user",
10+
11+
email_verified: true,
12+
name: "Test User",
13+
},
1414
};
1515

1616
// Configuration
1717
const configuration = {
18-
clients: [
19-
{
20-
client_id: "better-auth-dev",
21-
client_secret: "dev-secret-change-in-production",
22-
redirect_uris: [
23-
// Better Auth genericOAuth uses /oauth2/callback/:providerId
24-
"http://localhost:3000/api/auth/oauth2/callback/oidc",
25-
"http://localhost:3001/api/auth/oauth2/callback/oidc",
26-
"http://localhost:3002/api/auth/oauth2/callback/oidc",
27-
"http://localhost:3003/api/auth/oauth2/callback/oidc",
28-
],
29-
response_types: ["code"],
30-
grant_types: ["authorization_code", "refresh_token"],
31-
token_endpoint_auth_method: "client_secret_post",
32-
},
33-
],
34-
cookies: {
35-
keys: ["some-secret-key-for-dev"],
36-
},
37-
findAccount: async (ctx, id) => {
38-
const account = accounts[id];
39-
if (!account) return undefined;
18+
clients: [
19+
{
20+
client_id: "better-auth-dev",
21+
client_secret: "dev-secret-change-in-production",
22+
redirect_uris: [
23+
// Better Auth genericOAuth uses /oauth2/callback/:providerId
24+
"http://localhost:3000/api/auth/oauth2/callback/oidc",
25+
"http://localhost:3001/api/auth/oauth2/callback/oidc",
26+
"http://localhost:3002/api/auth/oauth2/callback/oidc",
27+
"http://localhost:3003/api/auth/oauth2/callback/oidc",
28+
],
29+
response_types: ["code"],
30+
grant_types: ["authorization_code", "refresh_token"],
31+
token_endpoint_auth_method: "client_secret_post",
32+
},
33+
],
34+
cookies: {
35+
keys: ["some-secret-key-for-dev"],
36+
},
37+
findAccount: async (ctx, id) => {
38+
const account = accounts[id];
39+
if (!account) return undefined;
4040

41-
return {
42-
accountId: id,
43-
async claims() {
44-
return {
45-
sub: id,
46-
email: account.email,
47-
email_verified: account.email_verified,
48-
name: account.name,
49-
};
50-
},
51-
};
52-
},
53-
// Simple interaction - auto-login for dev
54-
interactions: {
55-
url(ctx, interaction) {
56-
return `/interaction/${interaction.uid}`;
57-
},
58-
},
59-
features: {
60-
devInteractions: { enabled: true }, // Enable dev interactions for easy testing
61-
},
62-
claims: {
63-
email: ["email", "email_verified"],
64-
profile: ["name"],
65-
},
66-
ttl: {
67-
AccessToken: 3600, // 1 hour
68-
RefreshToken: 86400 * 30, // 30 days
69-
},
41+
return {
42+
accountId: id,
43+
async claims() {
44+
return {
45+
sub: id,
46+
email: account.email,
47+
email_verified: account.email_verified,
48+
name: account.name,
49+
};
50+
},
51+
};
52+
},
53+
// Simple interaction - auto-login for dev
54+
interactions: {
55+
url(ctx, interaction) {
56+
return `/interaction/${interaction.uid}`;
57+
},
58+
},
59+
features: {
60+
devInteractions: { enabled: true }, // Enable dev interactions for easy testing
61+
},
62+
claims: {
63+
email: ["email", "email_verified"],
64+
profile: ["name"],
65+
},
66+
ttl: {
67+
AccessToken: 3600, // 1 hour
68+
RefreshToken: 86400 * 30, // 30 days
69+
},
7070
};
7171

7272
const oidc = new Provider(ISSUER, configuration);
7373

7474
// Simple interaction endpoint for dev - auto-login as test-user
7575
oidc.use(async (ctx, next) => {
76-
if (ctx.path.startsWith("/interaction/")) {
77-
const uid = ctx.path.split("/")[2];
78-
const interaction = await oidc.interactionDetails(ctx.req, ctx.res);
76+
if (ctx.path.startsWith("/interaction/")) {
77+
const uid = ctx.path.split("/")[2];
78+
const interaction = await oidc.interactionDetails(ctx.req, ctx.res);
7979

80-
if (interaction.prompt.name === "login") {
81-
// Auto-login as test-user for dev
82-
await oidc.interactionFinished(
83-
ctx.req,
84-
ctx.res,
85-
{
86-
login: {
87-
accountId: "test-user",
88-
},
89-
},
90-
{ mergeWithLastSubmission: false },
91-
);
92-
return;
93-
}
80+
if (interaction.prompt.name === "login") {
81+
// Auto-login as test-user for dev
82+
await oidc.interactionFinished(
83+
ctx.req,
84+
ctx.res,
85+
{
86+
login: {
87+
accountId: "test-user",
88+
},
89+
},
90+
{ mergeWithLastSubmission: false },
91+
);
92+
return;
93+
}
9494

95-
if (interaction.prompt.name === "consent") {
96-
// Auto-consent for dev
97-
const grant = new oidc.Grant({
98-
accountId: interaction.session.accountId,
99-
clientId: interaction.params.client_id,
100-
});
95+
if (interaction.prompt.name === "consent") {
96+
// Auto-consent for dev
97+
const grant = new oidc.Grant({
98+
accountId: interaction.session.accountId,
99+
clientId: interaction.params.client_id,
100+
});
101101

102-
grant.addOIDCScope(
103-
interaction.params.scope
104-
?.split(" ")
105-
.filter((scope) => ["openid", "email", "profile"].includes(scope))
106-
.join(" ") || "openid email profile",
107-
);
102+
grant.addOIDCScope(
103+
interaction.params.scope
104+
?.split(" ")
105+
.filter((scope) => ["openid", "email", "profile"].includes(scope))
106+
.join(" ") || "openid email profile",
107+
);
108108

109-
await grant.save();
109+
await grant.save();
110110

111-
await oidc.interactionFinished(
112-
ctx.req,
113-
ctx.res,
114-
{
115-
consent: {
116-
grantId: grant.jti,
117-
},
118-
},
119-
{ mergeWithLastSubmission: true },
120-
);
121-
return;
122-
}
123-
}
124-
await next();
111+
await oidc.interactionFinished(
112+
ctx.req,
113+
ctx.res,
114+
{
115+
consent: {
116+
grantId: grant.jti,
117+
},
118+
},
119+
{ mergeWithLastSubmission: true },
120+
);
121+
return;
122+
}
123+
}
124+
await next();
125125
});
126126

127127
oidc.listen(PORT, () => {
128-
console.log(`🔐 OIDC Provider running at ${ISSUER}`);
129-
console.log(`📝 Client ID: better-auth-dev`);
130-
console.log(`🔑 Client Secret: dev-secret-change-in-production`);
131-
console.log(`👤 Test user: [email protected]`);
132-
console.log(
133-
`\n⚙️ Update your .env.local with:\nOIDC_CLIENT_ID=better-auth-dev\nOIDC_CLIENT_SECRET=dev-secret-change-in-production\nOIDC_ISSUER_URL=${ISSUER}`,
134-
);
128+
console.log(`🔐 OIDC Provider running at ${ISSUER}`);
129+
console.log(`📝 Client ID: better-auth-dev`);
130+
console.log(`🔑 Client Secret: dev-secret-change-in-production`);
131+
console.log(`👤 Test user: [email protected]`);
132+
console.log(
133+
`\n⚙️ Update your .env.local with:\nOIDC_CLIENT_ID=better-auth-dev\nOIDC_CLIENT_SECRET=dev-secret-change-in-production\nOIDC_ISSUER_URL=${ISSUER}`,
134+
);
135135
});

src/app/dashboard/page.tsx

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
import { auth } from "@/lib/auth";
21
import { headers } from "next/headers";
32
import { redirect } from "next/navigation";
3+
import { auth } from "@/lib/auth";
44

55
export default async function DashboardPage() {
6-
const session = await auth.api.getSession({
7-
headers: await headers(),
8-
});
6+
const session = await auth.api.getSession({
7+
headers: await headers(),
8+
});
99

10-
if (!session) {
11-
redirect("/login");
12-
}
10+
if (!session) {
11+
redirect("/login");
12+
}
1313

14-
return (
15-
<div className="flex min-h-screen items-center justify-center bg-zinc-50 dark:bg-black">
16-
<main className="flex flex-col items-center gap-8 rounded-lg bg-white p-12 shadow-lg dark:bg-zinc-900">
17-
<h1 className="text-3xl font-bold text-black dark:text-white">
18-
Hello World! 🎉
19-
</h1>
14+
return (
15+
<div className="flex min-h-screen items-center justify-center bg-zinc-50 dark:bg-black">
16+
<main className="flex flex-col items-center gap-8 rounded-lg bg-white p-12 shadow-lg dark:bg-zinc-900">
17+
<h1 className="text-3xl font-bold text-black dark:text-white">
18+
Hello World! 🎉
19+
</h1>
2020

21-
<div className="flex flex-col gap-4 text-center">
22-
<p className="text-zinc-600 dark:text-zinc-400">
23-
You are successfully authenticated!
24-
</p>
21+
<div className="flex flex-col gap-4 text-center">
22+
<p className="text-zinc-600 dark:text-zinc-400">
23+
You are successfully authenticated!
24+
</p>
2525

26-
<div className="rounded-lg bg-zinc-100 p-4 dark:bg-zinc-800">
27-
<p className="text-sm font-semibold text-zinc-800 dark:text-zinc-200">
28-
User Info:
29-
</p>
30-
<p className="text-zinc-600 dark:text-zinc-400">
31-
Email: <strong>{session.user.email}</strong>
32-
</p>
33-
<p className="text-zinc-600 dark:text-zinc-400">
34-
User ID: <strong>{session.user.id}</strong>
35-
</p>
36-
</div>
37-
</div>
26+
<div className="rounded-lg bg-zinc-100 p-4 dark:bg-zinc-800">
27+
<p className="text-sm font-semibold text-zinc-800 dark:text-zinc-200">
28+
User Info:
29+
</p>
30+
<p className="text-zinc-600 dark:text-zinc-400">
31+
Email: <strong>{session.user.email}</strong>
32+
</p>
33+
<p className="text-zinc-600 dark:text-zinc-400">
34+
User ID: <strong>{session.user.id}</strong>
35+
</p>
36+
</div>
37+
</div>
3838

39-
<form action="/api/auth/sign-out" method="POST">
40-
<button
41-
type="submit"
42-
className="rounded-full bg-red-600 px-6 py-3 text-white transition-colors hover:bg-red-700"
43-
>
44-
Sign Out
45-
</button>
46-
</form>
47-
</main>
48-
</div>
49-
);
39+
<form action="/api/auth/sign-out" method="POST">
40+
<button
41+
type="submit"
42+
className="rounded-full bg-red-600 px-6 py-3 text-white transition-colors hover:bg-red-700"
43+
>
44+
Sign Out
45+
</button>
46+
</form>
47+
</main>
48+
</div>
49+
);
5050
}

0 commit comments

Comments
 (0)