Compare commits
No commits in common. "c6758721ecd578b0c319c0c6d858fe932a65050a" and "6134e9a6ecf775200d967cc78e3c2b45bbc31da9" have entirely different histories.
c6758721ec
...
6134e9a6ec
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -35,8 +35,7 @@
|
|||
"pwa",
|
||||
"api",
|
||||
"ux",
|
||||
"route",
|
||||
"frontend"
|
||||
"route"
|
||||
],
|
||||
"[ignore]": {
|
||||
"editor.defaultFormatter": "foxundermoon.shell-format"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
"$fresh/": "https://deno.land/x/fresh@1.6.8/",
|
||||
"$std/": "https://deno.land/std@0.208.0/",
|
||||
"@cohabit/cohamail/": "./packages/@cohabit__cohamail@0.2.1/",
|
||||
"@cohabit/ressources_manager/": "./packages/@cohabit__ressources_manager@0.1.2/",
|
||||
"@cohabit/ressources_manager/": "./packages/@cohabit__ressources_manager@0.1.0/",
|
||||
"@jotsr/delayed": "jsr:@jotsr/delayed@^2.1.1",
|
||||
"@jotsr/smart-css-bundler": "jsr:@jotsr/smart-css-bundler@^0.3.0",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.2",
|
||||
|
@ -38,7 +38,7 @@
|
|||
"compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" },
|
||||
"workspaces": [
|
||||
"packages/@cohabit__cohamail@0.2.1",
|
||||
"packages/@cohabit__ressources_manager@0.1.2"
|
||||
"packages/@cohabit__ressources_manager@0.1.0"
|
||||
],
|
||||
"unstable": ["kv"]
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ import { cssBundler } from '@jotsr/smart-css-bundler/fresh'
|
|||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
cssBundler(['./src/stylesheets/main.css'] //TODO fix bundler out paths , { bundleSubDir: 'css' }
|
||||
),
|
||||
cssBundler(['./src/stylesheets/main.css'], { bundleSubDir: 'css' }),
|
||||
],
|
||||
})
|
||||
|
|
|
@ -35,7 +35,7 @@ export default function LoginForm() {
|
|||
|
||||
type LoginFormFields = {
|
||||
email: string
|
||||
passkey: 'on' | undefined
|
||||
passkey: boolean
|
||||
}
|
||||
|
||||
async function connect(event: Event) {
|
||||
|
@ -46,7 +46,7 @@ async function connect(event: Event) {
|
|||
|
||||
try {
|
||||
// User disable passkey
|
||||
if (fields.passkey !== 'on') {
|
||||
if (!fields.passkey) {
|
||||
throw new Error('User refused passkey')
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import 'npm:iterator-polyfill'
|
||||
// Polyfill AsyncIterator
|
||||
|
||||
import { FreshContext } from '$fresh/server.ts'
|
||||
import { FreshContext, Handlers } from '$fresh/server.ts'
|
||||
import { Contact, type Mail, send } from '@cohabit/cohamail/mod.ts'
|
||||
import { magicLinkTemplate } from '@cohabit/cohamail/templates/mod.ts'
|
||||
import { SessionHandlers } from '../../../src/session/mod.ts'
|
||||
import { SessionStore } from '../../../src/session/mod.ts'
|
||||
import { respondApi } from '../../../src/utils.ts'
|
||||
import { sleep } from '@jotsr/delayed'
|
||||
import { User } from '@cohabit/ressources_manager/src/models/mod.ts'
|
||||
|
@ -25,7 +25,7 @@ export async function getUserByMail(email: string): Promise<User | undefined> {
|
|||
return user
|
||||
}
|
||||
|
||||
export const handler: SessionHandlers = {
|
||||
export const handler: Handlers = {
|
||||
async POST(request, ctx) {
|
||||
const { email } = await request.json() as { email: string }
|
||||
|
||||
|
@ -42,7 +42,8 @@ export const handler: SessionHandlers = {
|
|||
`${ctx.url.origin}/api/magiclink?token=${token}&redirect=/profil`
|
||||
|
||||
// save token to session
|
||||
ctx.state.session.flash<MagicLinkInfos>(`MAGIC_LINK__${token}`, {
|
||||
const session = SessionStore.getFromRequest(request)
|
||||
session?.flash<MagicLinkInfos>(`MAGIC_LINK__${token}`, {
|
||||
email,
|
||||
remoteId: remoteId(ctx),
|
||||
timestamp: Date.now(),
|
||||
|
@ -69,16 +70,22 @@ export const handler: SessionHandlers = {
|
|||
)
|
||||
}
|
||||
},
|
||||
async GET(_request, ctx) {
|
||||
async GET(request, ctx) {
|
||||
const token = ctx.url.searchParams.get('token')
|
||||
const redirect = ctx.url.searchParams.get('redirect')
|
||||
const session = SessionStore.getFromRequest(request)
|
||||
|
||||
// no session datas
|
||||
if (session === undefined) {
|
||||
return respondApi('error', 'no session datas', 401)
|
||||
}
|
||||
|
||||
// no token
|
||||
if (token === null) {
|
||||
return respondApi('error', 'no token provided', 400)
|
||||
}
|
||||
// wrong or timeout token
|
||||
const entry = ctx.state.session.get<MagicLinkInfos>(`MAGIC_LINK__${token}`)
|
||||
const entry = session.get<MagicLinkInfos>(`MAGIC_LINK__${token}`)
|
||||
|
||||
const lifespan = Date.now() - 10 * 60 * 1_000 // ten minutes
|
||||
|
||||
|
@ -89,7 +96,7 @@ export const handler: SessionHandlers = {
|
|||
// check remote id (same user/machine that has query the token)
|
||||
if (entry.remoteId === remoteId(ctx)) {
|
||||
const user = await getUserByMail(entry.email)
|
||||
ctx.state.session.set('user', user)
|
||||
session.set('user', user)
|
||||
|
||||
if (redirect) {
|
||||
return Response.redirect(new URL(redirect, ctx.basePath))
|
||||
|
|
|
@ -5,15 +5,14 @@ import groups from './mock/groups.json' with { type: 'json' }
|
|||
import users from './mock/users.json' with { type: 'json' }
|
||||
import { User } from '@cohabit/ressources_manager/src/models/mod.ts'
|
||||
import { MailAddress } from '@cohabit/ressources_manager/types.ts'
|
||||
import { exists } from '$std/fs/exists.ts'
|
||||
import { existsSync } from '$std/fs/exists.ts'
|
||||
|
||||
const dbPath = './_fresh/db.sqlite'
|
||||
const dbExist = await exists(dbPath)
|
||||
|
||||
export const db = await Db.init(dbPath)
|
||||
|
||||
|
||||
//! Temp for demo only
|
||||
if (!dbExist) {
|
||||
if (!sessionStorage.getItem('db-loaded') && !existsSync(dbPath)) {
|
||||
console.log('=============LOAD DB=============')
|
||||
|
||||
// Load groups to DB
|
||||
|
@ -38,4 +37,6 @@ if (!dbExist) {
|
|||
|
||||
db.ressource.user.set([user])
|
||||
}
|
||||
|
||||
sessionStorage.setItem('db-loaded', 'true')
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue