19 lines
511 B
TypeScript
19 lines
511 B
TypeScript
import { OAuth, RedisTokenStore } from './oauth.ts';
|
|
import { useContextKey } from '@kevisual/use-config/context';
|
|
import { Redis } from 'ioredis';
|
|
|
|
export const oauth = useContextKey('oauth', () => {
|
|
const redis = useContextKey<Redis>('redis');
|
|
const store = new RedisTokenStore(redis);
|
|
// redis是promise
|
|
if (redis instanceof Promise) {
|
|
redis.then((r) => {
|
|
store.setRedis(r);
|
|
});
|
|
} else if (redis) {
|
|
store.setRedis(redis);
|
|
}
|
|
const oauth = new OAuth(store);
|
|
return oauth;
|
|
});
|