Giter VIP home page Giter VIP logo

sapper-authentication-demo's Introduction

Sapper Authentication Demo

A demonstration of Authentication with Sapper. This example is intentionally simple, but demonstrates a basic auth flow with JWT, secure cookies, and Sapper.

Includes:

  • JWT
  • Secure cookies
  • HTTP Only cookies

Installing

cd server
npm i
cd ..
npm i

Usage

npm run dev

sapper-authentication-demo's People

Contributors

antony avatar benmccann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sapper-authentication-demo's Issues

Strategy Configuration Questions

Thank you! I really enjoyed the talk and have now watched it twice. I think this is a much-needed resource—certainly much-needed by me.

I was having some trouble getting the /whoami route to work. I think there may be two issues, but I'm certainly not an expert:

  1. The validate function in the strategy configuration seems to be expecting the decoded JWT to contain an id, a role, and a scope. In the example, however, the JWT is created with an email, scope, and name. This seems to be a mismatch.

  2. Because there is no default auth configured (server.auth.default) and because auth is not configured for the /whoami route (config: {auth: "jwt"}), I think that that request.auth.credentials will always be null. I kept getting a 204 ("No Content") response, for example, whether I was signed in or not. To get the route to pipe the token through the authentication strategy, I configure authentication for the route (config: {auth: "jwt"}). But that caused me to get an "invalid_token" response. Digging into the hapi-auth-jwt2 documentation, I saw that setting the key is a required field. Setting that to my secret key seems to have fixed the issue. I know that you said in the talk that in a production app you would, of course, verify the token and, if invalid, sign the user out. It might be helpful to add those details to this demo. I realize that you are trying to keep things as simple as possible, but it would seem that verifying the JWT is essential to an authentication example.

Again, I'm certainly not an expert. Even if I'm missing something basic here, I hope that this question will be helpful to others who may be wondering about the same things. And thank you again for putting together this demo and for doing the talk.

Backend won't start getting this error

First of all thank you for putting this together, I am managing my jwt-token in the client side of sapper and found your tutorial witch is awesome and necessary to clear my head about having client and server running for a front end ;)

Back end server won't start for me.

/Users/oscar/Downloads/sapper-authentication-demo-master/backend/node_modules/@hapi/hapi/lib/core.js:51
    actives = new WeakMap(); 

SyntaxError: Unexpected token =
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/Users/oscar/Downloads/sapper-authentication-demo-master/backend/node_modules/@hapi/hapi/lib/server.js:9:14)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

Example is insecure by default

Hello,

IIUC, the server will accept any JWT.

const profile = token ? jwt.decode(token) : false;
// omitted code
authenticated: !!profile

If so, this is a big security vulnerability in what seems to be one of the most widely cited examples of implementing auth for Sapper applications. I think we should update the example to use jwt.verify.

Not always SSR

Sometimes, I need client request get some json data, like ajax.

How should I do for jwt auth?

client ajax request -> backend
client ajax request -> sapper(jwt) -> backend

Thanks!

Sessions not update dynamically

Hi,

I can easily run the project in giant mode. There is no problem but the sessions are not updated when I run the project in build mode. When I log out and log in to another user type, old data remains on the screen. I need to refresh the page from chrome for the session update. By the way, I did not make the slightest change in the project.

My build process;

npm run build -> in main directory
npm start -> in main directory

node server.js -> in backend/ directory.

I am getting this error when I run npm run dev

I downloaded the repo and npm i on both backend and root an getting the error below.

✗ client
'import' and 'export' may only appear at the top level
11: }
12: 
13: export function connect(port) {
    ^
14:   if (source || !window.EventSource) return;
✗ server
'import' and 'export' may only appear at the top level
11: }
12: 
13: export function connect(port) {
    ^
14:   if (source || !window.EventSource) return;
✔ service worker (188ms)
internal/modules/cjs/loader.js:969
    throw err;
    ^

Error: Cannot find module '/storage/sapper-authentication-demo-master/__sapper__/dev/server/server.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:17)
    at Function.Module._load (internal/modules/cjs/loader.js:859:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
> Server crashed

Error with yarn dev

Hi,
when I do a yarn dev doesn't work, it gives me back:

Error: Cannot find module '@hapi/hapi'

I don't understand if I should install it on my own, because in your video I don't see that it takes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.