You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

28 lines
628 B

import {
AUTH_SESSION_STATE_KEY,
DEFAULT_AUTH_SESSION_STATE,
type AuthSessionState,
} from "../composables/useAuthSession";
import { getCurrentUser } from "#server/utils/context";
export default defineNuxtPlugin(async () => {
const event = useRequestEvent();
if (!event) {
return;
}
const state = useState<AuthSessionState>(AUTH_SESSION_STATE_KEY, () => ({
...DEFAULT_AUTH_SESSION_STATE,
}));
if (state.value.initialized) {
return;
}
const user = await getCurrentUser(event);
state.value = {
initialized: true,
pending: false,
loggedIn: Boolean(user),
user: user,
};
});