add login sdk

This commit is contained in:
2024-06-26 09:52:53 +02:00
parent ed63ca77d6
commit 4ecf93d31b
11 changed files with 770 additions and 54 deletions

View File

@@ -1,15 +1,20 @@
import express from 'express';
import path from 'path';
import fs from 'fs';
import bodyParser from 'body-parser';
import jwt from 'jsonwebtoken';
import cors from 'cors';
import account from './account';
import sdk from 'oauth-janishutz-client-server';
declare let __dirname: string | undefined
if ( typeof( __dirname ) === 'undefined' ) {
__dirname = path.resolve( path.dirname( '' ) );
}
// TODO: Change config file, as well as in main.ts, index.html, oauth, if deploying there
const sdkConfig = JSON.parse( '' + fs.readFileSync( path.join( __dirname + '/config/sdk.config.testing.json' ) ) );
// const sdkConfig: AuthSDKConfig = JSON.parse( '' + fs.readFileSync( path.join( __dirname + '/config/sdk.config.secret.json' ) ) );
const run = () => {
let app = express();
app.use( cors( {
@@ -17,8 +22,29 @@ const run = () => {
origin: true
} ) );
// Load id.janishutz.com SDK and allow signing in
sdk.routes( app, ( uid: string ) => {
return new Promise( ( resolve, reject ) => {
account.checkUser( uid ).then( stat => {
resolve( stat );
} ).catch( e => {
reject( e );
} );
} );
},
( uid: string, email: string, username: string ) => {
return new Promise( ( resolve, reject ) => {
account.createUser( uid, username, email ).then( stat => {
resolve( stat );
} ).catch( e => {
reject( e );
} );
} );
}, sdkConfig );
app.get( '/', ( request, response ) => {
response.send( 'HELLO WORLD' );
response.send( 'Please visit <a href="https://music.janishutz.com">https://music.janishutz.com</a> to use this service' );
} );