cookies working for some raeson now

This commit is contained in:
ntr committed 2022-08-08 21:36:46 +10:00
1 parent 413aeedadf
commit 65e603f222
4 files changed
+31 -16

No files matched your search

+2 -3
View File
@@ -104,11 +104,11 @@ export default function createApi(log: Log, pg: Pg, discogs) {
}); });
} }
app.use(cors({ origin: false, credentials: true })); app.use(cors({ credentials: true }));
app.use(bodyParser()) app.use(bodyParser())
app.keys = [SECRET]; app.keys = [SECRET];
app.use(session(app)); app.use(session({ sameSite: 'None' }, app));
const { authRouter, passport } = routerAuth(log, pg); const { authRouter, passport } = routerAuth(log, pg);
app.use(passport.initialize()); app.use(passport.initialize());
@@ -120,7 +120,6 @@ export default function createApi(log: Log, pg: Pg, discogs) {
}); });
async function requireAuth(ctx, next) { async function requireAuth(ctx, next) {
log.warn(ctx.isAuthenticated());
await next(); await next();
} }
+18 -7
View File
@@ -1,25 +1,36 @@
import axios from 'axios'; import axios from 'axios';
const API_URL = 'http://localhost:41337'; const api = axios.create({
baseURL: 'http://localhost:41337',
axios.defaults.withCredentials = true; withCredentials: true
axios.defaults.crossDomain = true; });
const actions = { const actions = {
getBundles: async () => { getBundles: async () => {
const { data: bundles } = await axios.get(`${API_URL}/bundles`); const res = await api.get('/bundles');
const { data: bundles } = res;
console.log(res);
return bundles; return bundles;
}, },
getUserOffers: async (state, userId) => { getUserOffers: async (state, userId) => {
const { data: offers } = await axios.get(`${API_URL}/user/${userId}/offers`); const { data: offers } = await api.get(`/user/${userId}/offers`);
return offers; return offers;
}, },
getOffers: async (userId) => { getOffers: async (userId) => {
const { data } = await axios.get(`${API_URL}/user/${userId}/offers`); const { data } = await api.get(`/user/${userId}/offers`);
return data; return data;
}, },
postLogin: async (email, password) => {
const res = await api.post('/auth/login', {
email,
password,
});
return res.data;
},
}; };
export default actions; export default actions;
+2 -6
View File
@@ -1,17 +1,13 @@
import { h } from 'preact'; import { h } from 'preact';
import { useState, useEffect } from 'preact/hooks'; import { useState, useEffect } from 'preact/hooks';
import axios from 'axios'; import actions from './../actions';
const Register = () => { const Register = () => {
const [email, setEmail] = useState('') const [email, setEmail] = useState('')
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
async function postLogin() { async function postLogin() {
const { data } = await axios.post(`http://localhost:41337/auth/login`, { actions.postLogin(email, password);
email,
password,
});
console.log(data);
} }
function handleSubmit(e) { function handleSubmit(e) {
+9
View File
@@ -12,6 +12,15 @@ services:
volumes: volumes:
- "./db:/var/lib/postgresql/data" - "./db:/var/lib/postgresql/data"
pg-test:
image: postgres:latest
environment:
POSTGRES_USER: 'mcrates'
POSTGRES_DB: 'test'
POSTGRES_PASSWORD: 'digdeep'
ports:
- '55432:5432'
# api: # api:
# image: node:16 # image: node:16
# working_dir: /opt/mcrates/api # working_dir: /opt/mcrates/api