Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

implement this.redirect in preload #127

Merged
merged 4 commits into from
Feb 18, 2018
Merged

implement this.redirect in preload #127

merged 4 commits into from
Feb 18, 2018

Conversation

Rich-Harris
Copy link
Member

This adds a redirect method in preload, allowing this sort of thing:

<script>
  import auth from './_auth.js';

  export default {
    preload({ session }) {
      const user = session ? session.user : auth.user; // `session` on server, `auth` on client
      if (user) {
        return { user };
      } else {
        this.redirect(302, '/login');
      }
    }
  };
</script>

This fixes #83. Next up, a similar this.error(404, 'Not found') method.

@Rich-Harris Rich-Harris merged commit 4ca8195 into master Feb 18, 2018
@Rich-Harris Rich-Harris deleted the gh-83 branch February 18, 2018 15:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support server side goto?
1 participant