Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New hook onSessionBegin() #1613

Open
brillout opened this issue Apr 16, 2024 · 4 comments
Open

New hook onSessionBegin() #1613

brillout opened this issue Apr 16, 2024 · 4 comments
Labels

Comments

@brillout
Copy link
Member

brillout commented Apr 16, 2024

Description

New hook called right after renderPage() (before routing). I.e. it would be the first hook called upon rendering a page.

Thanks to #1588, the hook could be used for the server- and/or client-side.

Use case:

  • Init the vue-query client.
  • Init authentication for SSG apps. (See comment below.)

Potential alternative: https://vike.dev/onBeforeRoute.

@brillout brillout added the enhancement ✨ New feature or request label Apr 16, 2024
@bravius
Copy link

bravius commented Jun 26, 2024

Such a hook would be useful for globally transforming context, such as reconstituting a session class on the client from properties, prior to all other hooks, like guard.

Example:

file: +onRequestBegin.client.ts

export function onRequestBegin(pageContext:PageContext) {
   pageContext.session = new UserSession(pageContext.session);
}

onBeforeRoute does not seem to work in this case because the hook is not invoked on the client on first render, only on navigation.

+1 to have this hook implemented.

@brillout
Copy link
Member Author

I think you can use onRenderClient() or onBeforeRenderClient() instead?

We should document this somewhere, this is particularly relevant for SSG folks.

@bravius
Copy link

bravius commented Jun 26, 2024

I have a use case where this needs to happen before the guard hook is called. The documentation indicates onRenderClient() and onBeforeRenderClient() are ordered to occur after guard.

@brillout brillout changed the title New hook onRequestBegin() New hook onSessionBegin() Jun 26, 2024
@brillout
Copy link
Member Author

Makes sense, bumped its priority for the v1-release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants