# @svelte-dev/auth-github

> Github Strategy for Svelte Auth

Latest version **1.0.0** (published 2023-12-09) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @svelte-dev/auth-github
pnpm add @svelte-dev/auth-github
yarn add @svelte-dev/auth-github
bun add @svelte-dev/auth-github
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-12-09 |
| First published | 2023-12-07 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 23.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Willin Wang |
| Maintainers | willin |
| Keywords | svelte, auth, authentication, local, auth0, authing, oauth2, github, strategies |

## Links

- npm: https://www.npmjs.com/package/@svelte-dev/auth-github
- Repository: https://github.com/willin/svelte-turbo
- Homepage: https://svelte.js.cool
- Issues: https://github.com/willin/svelte-turbo/issues
- npm.io page: https://npm.io/package/@svelte-dev/auth-github

## Dependencies (1)

- [@svelte-dev/auth-oauth2](https://npm.io/package/@svelte-dev/auth-oauth2.md) *

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2023-12-09
- 0.1.1 — 2023-12-08
- 0.1.0 — 2023-12-07

## README

![Logo](https://repository-images.githubusercontent.com/726691357/f09bf6fc-3844-4584-8eee-6bfb425d8a38)

# @svelte-dev/auth-github strategy

The Github strategy is used to authenticate users against a github account. It extends the OAuth2Strategy.

For more details: <https://github.com/willin/svelte-turbo>

## Supported runtimes

| Runtime    | Has Support |
| ---------- | ----------- |
| Node.js    | ✅          |
| Cloudflare | ✅          |
| Vercel     | ✅          |

## Usage

### Create an OAuth application

Follow the steps on [the GitHub documentation](https://docs.github.com/en/developers/apps/building-oauth-apps/creating-an-oauth-app) to create a new application and get a client ID and secret.

### Create the strategy instance

```ts
import { GitHubStrategy } from '@svelte-dev/auth-github';

let gitHubStrategy = new GitHubStrategy(
  {
    clientID: 'YOUR_CLIENT_ID',
    clientSecret: 'YOUR_CLIENT_SECRET',
    callbackURL: 'https://example.com/auth/github/callback'
  },
  async ({ accessToken, extraParams, profile }) => {
    // Get the user data from your DB or API using the tokens and profile
    return User.findOrCreate({ email: profile.emails[0].value });
  }
);

auth.use(gitHubStrategy);
```

### Setup your routes

```html
<form action="/auth/github" method="get">
  <button>Login with Github</button>
</form>
```

```tsx
// routes/auth/github/+server
import { authenticator } from '~/auth.server';
import type { RequestHandler } from './$types';

export const POST: RequestHandler = async (event) => {
  return authenticator.authenticate('github', event);
};
```

```tsx
// routes/auth/github/callback/+server
import { authenticator } from '~/auth.server';
import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ event }) => {
  return authenticator.authenticate('github', event, {
    successRedirect: '/dashboard',
    failureRedirect: '/login'
  });
};
```

## 赞助 Sponsor

维护者 Owner： [Willin Wang](https://willin.wang)

如果您对本项目感兴趣，可以通过以下方式支持我：

- 关注我的 Github 账号：[@willin](https://github.com/willin) [![github](https://img.shields.io/github/followers/willin.svg?style=social&label=Followers)](https://github.com/willin)
- 参与 [爱发电](https://afdian.net/@willin) 计划
- 支付宝或微信[扫码打赏](https://user-images.githubusercontent.com/1890238/89126156-0f3eeb80-d516-11ea-9046-5a3a5d59b86b.png)

Donation ways:

- Github: <https://github.com/sponsors/willin>
- Paypal: <https://paypal.me/willinwang>
- Alipay or Wechat Pay: [QRCode](https://user-images.githubusercontent.com/1890238/89126156-0f3eeb80-d516-11ea-9046-5a3a5d59b86b.png)

## 许可证 License

Apache-2.0

---
_Source: https://npm.io/package/@svelte-dev/auth-github · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
