Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/AmruthPillai/next-auth-hasura-adapter
This is the Hasura Adapter for next-auth. This package can only be used in conjunction with the primary next-auth package. It is not a standalone package.
https://github.com/AmruthPillai/next-auth-hasura-adapter
Last synced: about 2 months ago
JSON representation
This is the Hasura Adapter for next-auth. This package can only be used in conjunction with the primary next-auth package. It is not a standalone package.
- Host: GitHub
- URL: https://github.com/AmruthPillai/next-auth-hasura-adapter
- Owner: AmruthPillai
- License: mit
- Created: 2022-08-16T12:44:10.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-16T13:50:48.000Z (6 months ago)
- Last Synced: 2024-05-02T05:37:17.779Z (5 months ago)
- Language: TypeScript
- Size: 445 KB
- Stars: 26
- Watchers: 4
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Hasura Adapter - NextAuth.js
Open Source. Full Stack. Own Your Data.
## Overview
This is the Hasura Adapter for [`next-auth`](https://next-auth.js.org). This package can only be used in conjunction with the primary `next-auth` package. It is not a standalone package.
You can find the Hasura + NextAuth integration docs at [hasura.io/learn/graphql/hasura-authentication/integrations/nextjs-auth](https://hasura.io/learn/graphql/hasura-authentication/integrations/nextjs-auth/).
## Getting Started
1. Install `next-auth` and `next-auth-hasura-adapter` as well as `hasura-cli`.
```sh
npm install next-auth next-auth-hasura-adapter hasura-cli
```2. Install the Hasura CLI, and dive into the console
```sh
hasura init
cd hasura && hasura console
```3. Add the NextAuth models to your database through SQL
```sql
CREATE EXTENSION IF NOT EXISTS pgcrypto;SET check_function_bodies = false;
CREATE TABLE public.accounts (
id uuid DEFAULT public.gen_random_uuid() NOT NULL,
type text NOT NULL,
provider text NOT NULL,
"providerAccountId" text NOT NULL,
refresh_token text,
access_token text,
expires_at bigint,
token_type text,
scope text,
id_token text,
session_state text,
oauth_token_secret text,
oauth_token text,
"userId" uuid NOT NULL,
refresh_token_expires_in bigint
);CREATE TABLE public.sessions (
id uuid DEFAULT public.gen_random_uuid() NOT NULL,
"sessionToken" text NOT NULL,
"userId" uuid NOT NULL,
expires timestamptz
);CREATE TABLE public.users (
id uuid DEFAULT public.gen_random_uuid() NOT NULL,
name text,
email text,
"emailVerified" timestamptz,
image text
);CREATE TABLE public.verification_tokens (
token text NOT NULL,
identifier text NOT NULL,
expires timestamptz
);ALTER TABLE ONLY public.accounts
ADD CONSTRAINT accounts_pkey PRIMARY KEY (id);ALTER TABLE ONLY public.sessions
ADD CONSTRAINT sessions_pkey PRIMARY KEY (id);ALTER TABLE ONLY public.users
ADD CONSTRAINT users_email_key UNIQUE (email);ALTER TABLE ONLY public.users
ADD CONSTRAINT users_pkey PRIMARY KEY (id);ALTER TABLE ONLY public.verification_tokens
ADD CONSTRAINT verification_tokens_pkey PRIMARY KEY (token);ALTER TABLE ONLY public.accounts
ADD CONSTRAINT "accounts_userId_fkey" FOREIGN KEY ("userId") REFERENCES public.users(id) ON UPDATE RESTRICT ON DELETE CASCADE;ALTER TABLE ONLY public.sessions
ADD CONSTRAINT "sessions_userId_fkey" FOREIGN KEY ("userId") REFERENCES public.users(id) ON UPDATE RESTRICT ON DELETE CASCADE;
```You can also find this file in `src/data/nextauth.sql`.
4. Add this adapter to your `pages/api/[...nextauth].js` next-auth configuration object.
```js
import NextAuth from "next-auth";
import { HasuraAdapter } from "next-auth-hasura-adapter";export default NextAuth({
providers: [],
adapter: HasuraAdapter({
endpoint: HASURA_API_ENPOINT,
admin_secret: HASURA_ADMIN_SECRET,
}),
});
```## Contributing
We're open to all community contributions! If you'd like to contribute in any way, please read our [Contributing Guide](https://github.com/nextauthjs/next-auth/blob/main/CONTRIBUTING.md).
## License
MIT