23 lines
729 B
TypeScript
23 lines
729 B
TypeScript
import { APIEvent, json } from 'solid-start/api';
|
|
import { findUserByToken } from '~/lib/find-user-by-token';
|
|
import { readConfig } from '~/server-only-lib/read-config';
|
|
|
|
export async function GET({ params, env }: APIEvent) {
|
|
const { credentials } = readConfig();
|
|
const user = await findUserByToken(params.token, credentials);
|
|
console.log({ caller: 'api/conf GET', params, credentials, user });
|
|
if (!user) {
|
|
return json({ params, response: 'NOT FOUND' });
|
|
}
|
|
const { code, expiration } = user.$;
|
|
if (
|
|
!code ||
|
|
!expiration ||
|
|
params.code !== code ||
|
|
new Date() > new Date(expiration)
|
|
) {
|
|
return json({ params, response: 'NOT FOUND' });
|
|
}
|
|
return json({ params, response: 'OK', user });
|
|
}
|