mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-31 14:33:18 +02:00
Fix PKCE flow and clean up other flows
This commit is contained in:
19
plugins/auth-oauth2/src/getAccessTokenIfNotExpired.ts
Normal file
19
plugins/auth-oauth2/src/getAccessTokenIfNotExpired.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { Context } from '@yaakapp/api';
|
||||
import type { AccessToken } from './store';
|
||||
import { getToken } from './store';
|
||||
|
||||
export async function getAccessTokenIfNotExpired(
|
||||
ctx: Context,
|
||||
contextId: string,
|
||||
): Promise<AccessToken | null> {
|
||||
const token = await getToken(ctx, contextId);
|
||||
if (token == null || isTokenExpired(token)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
export function isTokenExpired(token: AccessToken) {
|
||||
return token.expiresAt && Date.now() > token.expiresAt;
|
||||
}
|
||||
Reference in New Issue
Block a user