miolo 3.0.0-beta.176 → 3.0.0-beta.178
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -24,21 +24,18 @@ import { init_session_middleware } from "./session/index.mjs"
|
|
|
24
24
|
// google_url_logout_redirect: '/'
|
|
25
25
|
// }
|
|
26
26
|
|
|
27
|
-
const def_get_user_id = (user,
|
|
27
|
+
const def_get_user_id = async (user, _ctx) => user?.id
|
|
28
28
|
|
|
29
|
-
const def_find_user_by_id = (_id,
|
|
30
|
-
|
|
31
|
-
done(err, null)
|
|
29
|
+
const def_find_user_by_id = async (_id, ctx) => {
|
|
30
|
+
throw new Error("You need to define auth.passport.find_user_by_id")
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
const def_local_auth_user = (_username, _password,
|
|
35
|
-
|
|
36
|
-
done(err, null)
|
|
33
|
+
const def_local_auth_user = async (_username, _password, _ctx) => {
|
|
34
|
+
throw new Error("You need to define auth.passport.local_auth_user")
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
const def_google_auth_user = (_accessToken, _refreshToken, _profile,
|
|
40
|
-
|
|
41
|
-
done(err, null)
|
|
37
|
+
const def_google_auth_user = async (_accessToken, _refreshToken, _profile, _ctx) => {
|
|
38
|
+
throw new Error("You need to define auth.passport.google_auth_user")
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
const init_passport_auth_middleware = (app, options, sessionConfig, cacheConfig) => {
|
|
@@ -82,10 +79,13 @@ const init_passport_auth_middleware = (app, options, sessionConfig, cacheConfig)
|
|
|
82
79
|
ctx.sessionId = ctx.session?.externalKey
|
|
83
80
|
? ctx.getSessionStoreKey(ctx.session?.externalKey)
|
|
84
81
|
: undefined
|
|
85
|
-
|
|
82
|
+
get_user_id_f(user, ctx).then((uid) => {
|
|
83
|
+
return done(null, uid || false)
|
|
84
|
+
})
|
|
86
85
|
} catch (error) {
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
const msg = `Error serializing user: ${error}`
|
|
87
|
+
ctx.miolo.logger.error(`[auth][passport] ${msg}`)
|
|
88
|
+
return done(null, false, { message: msg })
|
|
89
89
|
}
|
|
90
90
|
})
|
|
91
91
|
}
|
|
@@ -97,10 +97,13 @@ const init_passport_auth_middleware = (app, options, sessionConfig, cacheConfig)
|
|
|
97
97
|
ctx.sessionId = ctx.session?.externalKey
|
|
98
98
|
? ctx.getSessionStoreKey(ctx.session?.externalKey)
|
|
99
99
|
: undefined
|
|
100
|
-
|
|
100
|
+
find_user_by_id_f(id, ctx).then((user) => {
|
|
101
|
+
return done(null, user || false)
|
|
102
|
+
})
|
|
101
103
|
} catch (error) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
+
const msg = `Error deserializing user: ${error}`
|
|
105
|
+
ctx.miolo.logger.error(`[auth][passport] ${msg}`)
|
|
106
|
+
return done(null, false, { message: msg })
|
|
104
107
|
}
|
|
105
108
|
})
|
|
106
109
|
}
|
|
@@ -110,7 +113,15 @@ const init_passport_auth_middleware = (app, options, sessionConfig, cacheConfig)
|
|
|
110
113
|
ctx.sessionId = ctx.session?.externalKey
|
|
111
114
|
? ctx.getSessionStoreKey(ctx.session?.externalKey)
|
|
112
115
|
: undefined
|
|
113
|
-
|
|
116
|
+
try {
|
|
117
|
+
local_auth_user_f(username, password, ctx).then(([user, msg]) => {
|
|
118
|
+
return done(null, user || false, { message: msg || "" })
|
|
119
|
+
})
|
|
120
|
+
} catch (error) {
|
|
121
|
+
const msg = `Error local auth user: ${error}`
|
|
122
|
+
ctx.miolo.logger.error(`[auth][passport] ${msg}`)
|
|
123
|
+
return done(null, false, { message: msg })
|
|
124
|
+
}
|
|
114
125
|
})
|
|
115
126
|
|
|
116
127
|
let google_strategy
|
|
@@ -128,7 +139,15 @@ const init_passport_auth_middleware = (app, options, sessionConfig, cacheConfig)
|
|
|
128
139
|
ctx.sessionId = ctx.session?.externalKey
|
|
129
140
|
? ctx.getSessionStoreKey(ctx.session?.externalKey)
|
|
130
141
|
: undefined
|
|
131
|
-
|
|
142
|
+
try {
|
|
143
|
+
google_auth_user_f(accessToken, refreshToken, profile, ctx).then(([user, msg]) => {
|
|
144
|
+
return done(null, user || false, { message: msg || "" })
|
|
145
|
+
})
|
|
146
|
+
} catch (error) {
|
|
147
|
+
const msg = `Error google auth user: ${error}`
|
|
148
|
+
ctx.miolo.logger.error(`[auth][passport] ${msg}`)
|
|
149
|
+
return done(null, false, { message: msg })
|
|
150
|
+
}
|
|
132
151
|
}
|
|
133
152
|
)
|
|
134
153
|
}
|
package/template/.env
CHANGED
|
@@ -32,6 +32,7 @@ MIOLO_AUTH_GOOGLE_CALLBACK_URL=/auth/google/callback
|
|
|
32
32
|
# Session
|
|
33
33
|
#
|
|
34
34
|
|
|
35
|
+
MIOLO_SESSION_KEY='miolo-sample.sess'
|
|
35
36
|
MIOLO_SESSION_SALT=00000000-0000-0000-0000-000000000000
|
|
36
37
|
MIOLO_SESSION_SECRET=00000000-0000-0000-0000-000000000000
|
|
37
38
|
MIOLO_SESSION_MAX_AGE=864000000
|
package/template/package.json
CHANGED
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"intre": "^3.0.0-beta.4",
|
|
45
45
|
"joi": "^18.1.2",
|
|
46
46
|
"lucide-react": "^1.8.0",
|
|
47
|
-
"miolo-cli": "^3.0.0-beta.
|
|
47
|
+
"miolo-cli": "^3.0.0-beta.178",
|
|
48
48
|
"miolo-model": "file:../miolo-model",
|
|
49
|
-
"miolo-react": "^3.0.0-beta.
|
|
49
|
+
"miolo-react": "^3.0.0-beta.178",
|
|
50
50
|
"next-themes": "^0.4.6",
|
|
51
51
|
"radix-ui": "^1.4.3",
|
|
52
52
|
"react": "^19.2.5",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@biomejs/biome": "2.4.12",
|
|
64
|
-
"miolo": "^3.0.0-beta.
|
|
64
|
+
"miolo": "^3.0.0-beta.178",
|
|
65
65
|
"sass-embedded": "^1.99.0"
|
|
66
66
|
},
|
|
67
67
|
"overrides": {
|
|
@@ -4,56 +4,31 @@ import {
|
|
|
4
4
|
db_user_find_or_create_from_google
|
|
5
5
|
} from "#server/db/io/users/auth.mjs"
|
|
6
6
|
|
|
7
|
-
const get_user_id = (user,
|
|
7
|
+
const get_user_id = async (user, ctx) => {
|
|
8
8
|
ctx.miolo.logger.debug(
|
|
9
9
|
`[auth][local] get_user_id() - name ${user?.name} - sessionId ${ctx.sessionId}`
|
|
10
10
|
)
|
|
11
|
-
|
|
12
|
-
if (uid !== undefined) {
|
|
13
|
-
return done(undefined, uid)
|
|
14
|
-
} else {
|
|
15
|
-
const err = new Error("User object is missing an ID for serialization")
|
|
16
|
-
return done(err, undefined)
|
|
17
|
-
}
|
|
11
|
+
return user?.id
|
|
18
12
|
}
|
|
19
13
|
|
|
20
|
-
const find_user_by_id = (id,
|
|
14
|
+
const find_user_by_id = async (id, ctx) => {
|
|
21
15
|
ctx.miolo.logger.debug(
|
|
22
16
|
`[auth][local] find_user_by_id() - Searching user id ${id} - sessionId ${ctx.sessionId}`
|
|
23
17
|
)
|
|
24
|
-
db_find_user_by_id(ctx.miolo, id)
|
|
25
|
-
|
|
26
|
-
ctx.miolo.logger.debug("[auth][local] find_user_by_id() - User not found")
|
|
27
|
-
const err = new Error("User not found")
|
|
28
|
-
return done(err, undefined)
|
|
29
|
-
} else {
|
|
30
|
-
ctx.miolo.logger.debug("[auth][local] find_user_by_id() - User found", JSON.stringify(user))
|
|
31
|
-
return done(undefined, user)
|
|
32
|
-
}
|
|
33
|
-
})
|
|
18
|
+
const user = await db_find_user_by_id(ctx.miolo, id)
|
|
19
|
+
return user
|
|
34
20
|
}
|
|
35
21
|
|
|
36
|
-
const local_auth_user = (username, password,
|
|
22
|
+
const local_auth_user = async (username, password, ctx) => {
|
|
37
23
|
ctx.miolo.logger.debug(
|
|
38
24
|
`[auth][local] local_auth_user() - checking credentials for ${username} - sessionId ${ctx.sessionId}`
|
|
39
25
|
)
|
|
40
26
|
|
|
41
|
-
db_auth_user(ctx.miolo, username, password)
|
|
42
|
-
|
|
43
|
-
ctx.miolo.logger.debug(`[auth][local] local_auth_user() - User not logged in: ${msg}`)
|
|
44
|
-
|
|
45
|
-
const err = new Error(msg)
|
|
46
|
-
return done(err, undefined)
|
|
47
|
-
} else {
|
|
48
|
-
ctx.miolo.logger.debug(
|
|
49
|
-
`[auth][local] local_auth_user() - User logged in! Id: ${user?.id} Email ${user?.email}`
|
|
50
|
-
)
|
|
51
|
-
return done(undefined, user)
|
|
52
|
-
}
|
|
53
|
-
})
|
|
27
|
+
const [user, msg] = await db_auth_user(ctx.miolo, username, password)
|
|
28
|
+
return [user, msg]
|
|
54
29
|
}
|
|
55
30
|
|
|
56
|
-
const google_auth_user = async (_accessToken, _refreshToken, profile,
|
|
31
|
+
const google_auth_user = async (_accessToken, _refreshToken, profile, ctx) => {
|
|
57
32
|
try {
|
|
58
33
|
// Extract Google profile info
|
|
59
34
|
const google_id = profile.id
|
|
@@ -66,27 +41,17 @@ const google_auth_user = async (_accessToken, _refreshToken, profile, done, ctx)
|
|
|
66
41
|
`[auth][google] google_auth_user() - upsaving db user for ${email} - sessionId ${ctx.sessionId}`
|
|
67
42
|
)
|
|
68
43
|
|
|
69
|
-
|
|
44
|
+
const [user, msg] = await db_user_find_or_create_from_google(
|
|
70
45
|
ctx.miolo,
|
|
71
46
|
email,
|
|
72
47
|
name,
|
|
73
48
|
google_id,
|
|
74
49
|
google_picture
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
ctx.miolo.logger.debug(`[auth][google] google_auth_user() - Db user not found: ${msg}`)
|
|
78
|
-
const err = new Error(msg)
|
|
79
|
-
return done(err, undefined)
|
|
80
|
-
} else {
|
|
81
|
-
ctx.miolo.logger.debug(
|
|
82
|
-
`[auth][google] google_auth_user() - Db user found! Id: ${user?.id} Email ${user?.email}`
|
|
83
|
-
)
|
|
84
|
-
return done(undefined, user)
|
|
85
|
-
}
|
|
86
|
-
})
|
|
50
|
+
)
|
|
51
|
+
return [user, msg]
|
|
87
52
|
} catch (error) {
|
|
88
53
|
ctx.miolo.logger.error(`[auth][google] Error preparing db user: ${error}`)
|
|
89
|
-
return
|
|
54
|
+
return [undefined, error]
|
|
90
55
|
}
|
|
91
56
|
}
|
|
92
57
|
|