mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-19 10:08:12 +01:00
20 lines
496 B
TypeScript
20 lines
496 B
TypeScript
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;
|
|
}
|