The Afdian(爱发电) strategy is used to authenticate users against a afidan account. It extends the OAuth2Strategy.
For more details: https://github.com/willin/svelte-auth
Runtime | Has Support |
---|---|
Node.js | ✅ |
Cloudflare | ✅ |
Vercel | ✅ |
Follow the steps on the Afdian(爱发电) documentation to create a new application and get a client ID and secret.
import { AfdianStrategy } from '@svelte-dev/auth-afdian';
let strategy = new AfdianStrategy(
{
clientID: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
callbackURL: 'https://example.com/auth/afdian/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(strategy);
<form action="/auth/afdian" method="get">
<button>Login with Afdian(爱发电)</button>
</form>
// routes/auth/afdian/+server
import { authenticator } from '~/auth.server';
import type { RequestHandler } from './$types';
export const POST: RequestHandler = async (event) => {
return authenticator.authenticate('afdian', event);
};
// routes/auth/afdian/callback/+server
import { authenticator } from '~/auth.server';
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ event }) => {
return authenticator.authenticate('afdian', event, {
successRedirect: '/dashboard',
failureRedirect: '/login'
});
};
维护者 Owner: Willin Wang
如果您对本项目感兴趣,可以通过以下方式支持我:
Donation ways:
- Github: https://github.com/sponsors/willin
- Paypal: https://paypal.me/willinwang
- Alipay or Wechat Pay: QRCode
Apache-2.0