JSON parse error with oidcProvider and oidcClient()?

I'm encountering a weird error. I have two services, a vite/hono app serving as the oidc provider, and then a nextjs app serving as a client. Whenever I open up the vite/hono app and sign in to the oauth service, and then try to use the sign in button on the nextjs app, I encounter this error.
[0] # SERVER_ERROR: 955 | throw new APIError("UNAUTHORIZED", {
[0] 956 | error_description: "client is disabled",
[0] 957 | error: "invalid_client"
[0] 958 | });
[0] 959 | }
[0] 960 | const value = JSON.parse(
[0] ^
[0] SyntaxError: JSON Parse error: Unterminated string
[0] # SERVER_ERROR: 955 | throw new APIError("UNAUTHORIZED", {
[0] 956 | error_description: "client is disabled",
[0] 957 | error: "invalid_client"
[0] 958 | });
[0] 959 | }
[0] 960 | const value = JSON.parse(
[0] ^
[0] SyntaxError: JSON Parse error: Unterminated string
Which throws Error Code: oauth_code_verification_failed on the website.
2 Replies
Helix
HelixOP2mo ago
NextJS Config
import { betterAuth } from "better-auth";
import { genericOAuth } from "better-auth/plugins";
import { createPool } from "mysql2/promise";

const connectionString = process.env.APP_CONNECTION_URI;
if (!connectionString) {
throw new Error("APP_CONNECTION_URI environment variable is required");
}

export const auth = betterAuth({
database: createPool({
uri: connectionString,
}),
secret: process.env.BETTER_AUTH_SECRET || "default-dev-secret",
baseURL: process.env.BETTER_AUTH_URL || "http://localhost:3000",
session: {
expiresIn: 60 * 60 * 24 * 7, // 7 days
updateAge: 60 * 60 * 24, // 1 day
},
trustedOrigins: [
"http://localhost:3000", // Client app
],
plugins: [
genericOAuth({
config: [
{
providerId: "rfid-sso",
clientId: "eagle-web",
clientSecret: "eagle-secret",
discoveryUrl:
"http://localhost:8000/api/auth/.well-known/openid-configuration",
scopes: ["openid", "profile", "email"],
},
],
}),
],
});
import { betterAuth } from "better-auth";
import { genericOAuth } from "better-auth/plugins";
import { createPool } from "mysql2/promise";

const connectionString = process.env.APP_CONNECTION_URI;
if (!connectionString) {
throw new Error("APP_CONNECTION_URI environment variable is required");
}

export const auth = betterAuth({
database: createPool({
uri: connectionString,
}),
secret: process.env.BETTER_AUTH_SECRET || "default-dev-secret",
baseURL: process.env.BETTER_AUTH_URL || "http://localhost:3000",
session: {
expiresIn: 60 * 60 * 24 * 7, // 7 days
updateAge: 60 * 60 * 24, // 1 day
},
trustedOrigins: [
"http://localhost:3000", // Client app
],
plugins: [
genericOAuth({
config: [
{
providerId: "rfid-sso",
clientId: "eagle-web",
clientSecret: "eagle-secret",
discoveryUrl:
"http://localhost:8000/api/auth/.well-known/openid-configuration",
scopes: ["openid", "profile", "email"],
},
],
}),
],
});
"use client";

import { genericOAuthClient } from "better-auth/client/plugins";
import { createAuthClient } from "better-auth/react";

export const authClient = createAuthClient({
baseURL: "http://localhost:3000",
plugins: [genericOAuthClient()],
});
"use client";

import { genericOAuthClient } from "better-auth/client/plugins";
import { createAuthClient } from "better-auth/react";

export const authClient = createAuthClient({
baseURL: "http://localhost:3000",
plugins: [genericOAuthClient()],
});
Helix
HelixOP2mo ago
https://gist.github.com/cnbrown04/772a187d41de28ccf4e33a1d1cb6b474 Gist because discord wont let me send the other config...
Gist
auth-client.ts
GitHub Gist: instantly share code, notes, and snippets.

Did you find this page helpful?