fixed some error. Now this plugin are working

This commit is contained in:
doesnm 2025-01-16 13:23:37 +03:00
parent 11a8f0db3a
commit 3dd4c01e0d
Signed by: doesnm
SSH key fingerprint: SHA256:fSXBOeK0SXxGqmbQ2pKhSvH3TF0kCijXZfzh3gHfQYM
2 changed files with 18 additions and 13 deletions

29
main.js
View file

@ -16,7 +16,13 @@ async function register ({
private: true
})
registerSetting({
name: 'mail',
label: 'Mail',
type: 'input',
descriptionHTML: 'mail domain for each matrix user',
private: true
})
registerIdAndPassAuth({
authName: 'matrix',
@ -24,7 +30,6 @@ async function register ({
login: options => login(peertubeHelpers, settingsManager, options)
})
setWeight(500)
}
@ -42,6 +47,7 @@ async function login (peertubeHelpers, settingsManager, options) {
const settings = await settingsManager.getSettings([
'url',
'mail'
])
// options.id, options.password
@ -60,20 +66,19 @@ async function login (peertubeHelpers, settingsManager, options) {
initial_display_name: "PeerTube"
})}).then(f => f.json())
if(r.access_token){
const r2 = fetch(`https://${settings.url}/_matrix/client/v3/logout`, {
const r2 = await fetch(`https://${settings.url}/_matrix/client/v3/logout`, {
method: "POST",
headers: {
Authorization: r.access_token
Authorization: `Bearer ${r.access_token}`
}
});
if(r2.statusCode == 200){
return res(
options.id,
`${options.id}@0ut0f.space`
)
if(r2.status == 200){
return {
username: options.id,
email: `${options.id}@${settings.mail}`
}
}else{
logger.warn(`Logout of session failed with code ${r2.status}: ${await r2.text()}`);
}
}
}

View file

@ -1,6 +1,6 @@
{
"name": "peertube-plugin-auth-matrix",
"version": "0.0.14",
"version": "0.0.17",
"description": "Add Matrix support to login form in PeerTube.",
"engine": {
"peertube": ">=2.2.0"