19 lines
533 B
TypeScript
19 lines
533 B
TypeScript
import {getDataSource} from './db';
|
|
import {AuthSession} from './entity/AuthSession';
|
|
|
|
/** Returns the user authorized by a given session. */
|
|
export async function getUserFromSessionID (sessionID: string | undefined) {
|
|
const dataSource = await getDataSource();
|
|
const sessionsRepo = dataSource.getRepository(AuthSession);
|
|
const session = sessionID
|
|
? await sessionsRepo.findOne({
|
|
where: {id: sessionID},
|
|
relations: {
|
|
authMethod: {
|
|
user: true,
|
|
},
|
|
},
|
|
})
|
|
: null;
|
|
return session?.authMethod.user ?? null;
|
|
}
|