mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-15 19:44:48 +00:00
Work on login
This commit is contained in:
14
app/auth/validate.js
Normal file
14
app/auth/validate.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import jwt from 'jsonwebtoken'
|
||||
|
||||
const JWT_SECRET = 'put-your-JWT-secret-here'; // you can set this w/ an environment variable
|
||||
|
||||
export const authValidate = function(req) {
|
||||
try {
|
||||
return jwt.verify(req.cookies.ds, JWT_SECRET)
|
||||
} catch (error) {
|
||||
return {
|
||||
unauthorized: true,
|
||||
message: 'Unauthorized',
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,10 @@ import express from 'express';
|
||||
import bodyParser from 'body-parser';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import { authSetup } from './auth/setup';
|
||||
import { authValidate } from './auth/validate';
|
||||
import sapper from 'sapper';
|
||||
import compression from 'compression';
|
||||
import { Store } from 'svelte/store.js';
|
||||
// import { validate } from '../routes/_services/auth-check.js';
|
||||
import { manifest } from './manifest/server.js';
|
||||
|
||||
const { PORT, NODE_ENV } = process.env;
|
||||
@@ -25,9 +25,8 @@ authSetup(app)
|
||||
app.use(sapper({
|
||||
manifest,
|
||||
store: req => {
|
||||
// const user = validate(req);
|
||||
// return new Store({ user: user.unauthorized ? null : user });
|
||||
return new Store({ user: null });
|
||||
const user = authValidate(req);
|
||||
return new Store({ user: user.unauthorized ? null : user });
|
||||
},
|
||||
}))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user