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
591 B

import {
AUTH_SESSION_STATE_KEY,
DEFAULT_AUTH_SESSION_STATE,
type AuthSessionState,
} from "../composables/useAuthSession";
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 event.context.auth.getCurrent();
state.value = {
initialized: true,
pending: false,
loggedIn: Boolean(user),
user: user ?? null,
};
});