working
This commit is contained in:
parent
746e62d617
commit
ac7ead09c9
|
|
@ -26,6 +26,8 @@ services:
|
|||
NEXT_PUBLIC_API_URL: http://backend:8000
|
||||
NEXT_PUBLIC_DEMO_EMAIL: candidate@alabuga.space
|
||||
NEXT_PUBLIC_DEMO_PASSWORD: orbita123
|
||||
NEXT_PUBLIC_DEMO_HR_EMAIL: hr@alabuga.space
|
||||
NEXT_PUBLIC_DEMO_HR_PASSWORD: orbita123
|
||||
volumes:
|
||||
- ./frontend:/app
|
||||
- /app/node_modules
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ interface Submission {
|
|||
}
|
||||
|
||||
async function fetchModerationQueue() {
|
||||
const token = await getDemoToken();
|
||||
const token = await getDemoToken('hr');
|
||||
const submissions = await apiFetch<Submission[]>('/api/admin/submissions', { authToken: token });
|
||||
return submissions;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,36 @@
|
|||
import { apiFetch } from './api';
|
||||
|
||||
let cachedToken: string | null = null;
|
||||
type DemoRole = 'pilot' | 'hr';
|
||||
|
||||
export async function getDemoToken() {
|
||||
const tokenCache: Partial<Record<DemoRole, string>> = {};
|
||||
|
||||
function resolveCredentials(role: DemoRole) {
|
||||
if (role === 'hr') {
|
||||
const email = process.env.NEXT_PUBLIC_DEMO_HR_EMAIL ?? 'hr@alabuga.space';
|
||||
const password =
|
||||
process.env.NEXT_PUBLIC_DEMO_HR_PASSWORD ?? process.env.NEXT_PUBLIC_DEMO_PASSWORD ?? 'orbita123';
|
||||
return { email, password };
|
||||
}
|
||||
|
||||
return {
|
||||
email: process.env.NEXT_PUBLIC_DEMO_EMAIL ?? 'candidate@alabuga.space',
|
||||
password: process.env.NEXT_PUBLIC_DEMO_PASSWORD ?? 'orbita123'
|
||||
};
|
||||
}
|
||||
|
||||
export async function getDemoToken(role: DemoRole = 'pilot') {
|
||||
const cachedToken = tokenCache[role];
|
||||
if (cachedToken) {
|
||||
return cachedToken;
|
||||
}
|
||||
|
||||
const email = process.env.NEXT_PUBLIC_DEMO_EMAIL ?? 'candidate@alabuga.space';
|
||||
const password = process.env.NEXT_PUBLIC_DEMO_PASSWORD ?? 'orbita123';
|
||||
const credentials = resolveCredentials(role);
|
||||
|
||||
const data = await apiFetch<{ access_token: string }>('/auth/login', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ email, password })
|
||||
body: JSON.stringify(credentials)
|
||||
});
|
||||
|
||||
cachedToken = data.access_token;
|
||||
return cachedToken;
|
||||
tokenCache[role] = data.access_token;
|
||||
return data.access_token;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user