Skip to content
This repository was archived by the owner on Dec 9, 2023. It is now read-only.

Commit 534a14b

Browse files
committed
docs: 📝 update readme
1 parent 220ce44 commit 534a14b

File tree

1 file changed

+68
-34
lines changed

1 file changed

+68
-34
lines changed

README.md

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,92 @@
1-
# create-svelte
1+
![Logo](https://repository-images.githubusercontent.com/726691357/f09bf6fc-3844-4584-8eee-6bfb425d8a38)
22

3-
Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
3+
# svelte-auth-github strategy
44

5-
Read more about creating a library [in the docs](https://kit.svelte.dev/docs/packaging).
5+
The Github strategy is used to authenticate users against a github account. It extends the OAuth2Strategy.
66

7-
## Creating a project
7+
For more details: <https://github.com/willin/svelte-auth>
88

9-
If you're seeing this, you've probably already done this step. Congrats!
9+
## Supported runtimes
1010

11-
```bash
12-
# create a new project in the current directory
13-
npm create svelte@latest
11+
| Runtime | Has Support |
12+
| ---------- | ----------- |
13+
| Node.js ||
14+
| Cloudflare ||
15+
| Vercel ||
1416

15-
# create a new project in my-app
16-
npm create svelte@latest my-app
17-
```
17+
## Usage
1818

19-
## Developing
19+
### Create an OAuth application
2020

21-
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
21+
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.
2222

23-
```bash
24-
npm run dev
23+
### Create the strategy instance
2524

26-
# or start the server and open the app in a new browser tab
27-
npm run dev -- --open
28-
```
25+
```ts
26+
import { GitHubStrategy } from '@svelte-dev/auth-github';
2927

30-
Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
28+
let gitHubStrategy = new GitHubStrategy(
29+
{
30+
clientID: 'YOUR_CLIENT_ID',
31+
clientSecret: 'YOUR_CLIENT_SECRET',
32+
callbackURL: 'https://example.com/auth/github/callback'
33+
},
34+
async ({ accessToken, extraParams, profile }) => {
35+
// Get the user data from your DB or API using the tokens and profile
36+
return User.findOrCreate({ email: profile.emails[0].value });
37+
}
38+
);
3139

32-
## Building
40+
auth.use(gitHubStrategy);
41+
```
3342

34-
To build your library:
43+
### Setup your routes
3544

36-
```bash
37-
npm run package
45+
```html
46+
<form action="/auth/sso" method="get">
47+
<button>Login with SSO</button>
48+
</form>
3849
```
3950

40-
To create a production version of your showcase app:
51+
```tsx
52+
// routes/auth/github/+server
53+
import { authenticator } from '~/auth.server';
54+
import type { RequestHandler } from './$types';
55+
56+
export const POST: RequestHandler = async (event) => {
57+
return authenticator.authenticate('github', event);
58+
};
59+
```
4160

42-
```bash
43-
npm run build
61+
```tsx
62+
// routes/auth/github/callback/+server
63+
import { authenticator } from '~/auth.server';
64+
import type { PageServerLoad } from './$types';
65+
66+
export const load: PageServerLoad = async ({ event }) => {
67+
return authenticator.authenticate('github', event, {
68+
successRedirect: '/dashboard',
69+
failureRedirect: '/login'
70+
});
71+
};
4472
```
4573

46-
You can preview the production build with `npm run preview`.
74+
## 赞助 Sponsor
4775

48-
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
76+
维护者 Owner: [Willin Wang](https://willin.wang)
4977

50-
## Publishing
78+
如果您对本项目感兴趣,可以通过以下方式支持我:
5179

52-
Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
80+
- 关注我的 Github 账号:[@willin](https://github.com/willin) [![github](https://img.shields.io/github/followers/willin.svg?style=social&label=Followers)](https://github.com/willin)
81+
- 参与 [爱发电](https://afdian.net/@willin) 计划
82+
- 支付宝或微信[扫码打赏](https://user-images.githubusercontent.com/1890238/89126156-0f3eeb80-d516-11ea-9046-5a3a5d59b86b.png)
5383

54-
To publish your library to [npm](https://www.npmjs.com):
84+
Donation ways:
5585

56-
```bash
57-
npm publish
58-
```
86+
- Github: <https://github.com/sponsors/willin>
87+
- Paypal: <https://paypal.me/willinwang>
88+
- Alipay or Wechat Pay: [QRCode](https://user-images.githubusercontent.com/1890238/89126156-0f3eeb80-d516-11ea-9046-5a3a5d59b86b.png)
89+
90+
## 许可证 License
91+
92+
Apache-2.0

0 commit comments

Comments
 (0)