25 lines
728 B
JavaScript
25 lines
728 B
JavaScript
import { apiRequest } from './api.js';
|
|
|
|
export async function loadSession() {
|
|
const { user } = await apiRequest('/auth/me');
|
|
const name = document.querySelector('#profile-name');
|
|
if (name) name.textContent = user.name || user.email;
|
|
|
|
const image = document.querySelector('#profile-image');
|
|
if (image && user.picture) {
|
|
image.src = user.picture;
|
|
image.alt = `${user.name || user.email} 프로필`;
|
|
image.hidden = false;
|
|
}
|
|
return user;
|
|
}
|
|
|
|
export function bindLogout() {
|
|
document.querySelectorAll('[data-logout]').forEach((button) => {
|
|
button.addEventListener('click', async () => {
|
|
await apiRequest('/auth/logout', { method: 'POST' });
|
|
window.location.assign('/login');
|
|
});
|
|
});
|
|
}
|