@better-auth-extensions/yandex
v1.0.3
Published
Yandex extensions for better-auth
Downloads
85
Readme
better-auth-extensions/yandex
Yandex extensions and plugins for better-auth.
Installation
npm install @better-auth-extensions/yandexDocumentation
getYandexOAuthPlugin(clientId, clientSecret, permissions?)
Produces a Yandex-tailored configuration object which may be used as a Generic OAuth plugin. It takes in the Client ID, and Client Secret of the Yandex OAuth Application and an optional list of access permissions to be requested from the application.
Example
Including the Yandex plugin in the better-auth configuration:
auth.ts
import { betterAuth } from "better-auth";
import { genericOAuth } from "better-auth/plugins";
import { getYandexOAuthPlugin } from "@better-auth-extensions/yandex";
const yandexConfig = getYandexOAuthPlugin(
process.env.YANDEX_CLIENT_ID,
process.env.YANDEX_CLIENT_SECRET,
);
export const auth = betterAuth({
// ... other config options
plugins: [
genericOAuth({
config: [yandexConfig],
}),
],
});Setting up the better-auth client:
lib/auth-client.ts
import { createAuthClient } from "better-auth/react";
import { genericOAuthClient } from "better-auth/client/plugins";
export const { signIn, useSession } = createAuthClient({
plugins: [genericOAuthClient()],
});Using the Yandex plugin to sign in:
lib/components/SignInButton.tsx
import { signIn } from "../auth-client";
export default function SignInButton({ endpoint }: { endpoint: string }) {
return (
<button
onClick={() => {
signIn.oauth2({
providerId: "yandex",
callbackURL: endpoint,
});
}}
>
{"Sign in with Yandex"}
</button>
);
}Note
The plugin mounts a route to handle the OAuth callback: /oauth2/callback/yandex. This means that ${YOUR_BASE_URL}/api/auth/oauth2/callback/yandex will be used as the callback URL. Make sure your OAuth provider is configured to use this URL.
