Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
peterphanouvong committed May 26, 2022
1 parent a1313ab commit 35ef342
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ Kinde Auth for NextJS. Server-side with PKCE (OAuth2.1).

Get started in 5 minutes.

### Install

Install `@kinde-oss/kinde-auth-nextjs` as a dependency to your NextJS project.

```bash
npm i @kinde-oss/kinde-auth-nextjs
```

### Setup environment variables

Put these things in your `.env` file.
Put these variables in your `.env` file. You can find these variables on your Kinde `Settings` -> `App keys` page.

```bash
KINDE_DOMAIN='app.kinde.localtest.me'
KINDE_REDIRECT_URL='kinde.localtest.me'
KINDE_LOGOUT_URL='kinde.localtest.me/404'
CLIENT_ID='reg@live'
CLIENT_SECRET='[your secret]'
KINDE_REDIRECT_URL=[http://localhost:3000]
KINDE_ISSUER_URL=[https://your_kinde_domain]
KINDE_POST_LOGOUT_REDIRECT_ROUTE=/[your_logout_route]
KINDE_CLIENT_ID=[your_kinde_client_id]
KINDE_CLIENT_SECRET=[your_kinde_client_secret]
```

### Wrap your app in a KindeProvider
Expand All @@ -39,7 +47,7 @@ export default MyApp;

### Put in your API endpoints

Create a file at `myapp/pages/api/auth/[...kindeAuth].js`
Create a file `myapp/pages/api/auth/[...kindeAuth].js` inside your NextJS project.
Inside the file `[...kindeAuth].js` put this code:

```js
Expand All @@ -54,8 +62,12 @@ To access the user information, use the `useAuth` hook from any part of your app

```js
import styles from "../styles/Home.module.css";
import { useAuth } from "@kinde-oss/kinde-auth-nextjs";

export default function Home() {
const auth = useAuth();
console.log(auth);

return (
<div className={styles["link-list"]}>
<a href="/api/auth/me">get me</a>
Expand All @@ -67,4 +79,7 @@ export default function Home() {
}
```

Pointing to `/api/auth/login` will take you to the login page etc.
- `/api/auth/me` - this endpoint will get user information
- `/api/auth/login` - will redirect you to login at the KindeAuth server
- `/api/auth/logout` - will log you out of the app
- `/api/auth/register` - will redirect you to register at the KindeAuth server.

0 comments on commit 35ef342

Please sign in to comment.