i'm using nativescript but can't connect database is orientdb. i try npm install orientjs https://github.com/orientechnologies/orientjs but don't success. Please help me
After have run the command: npm install orientjs
Save this code in a file.js:
var OrientDB = require('orientjs');
var server = OrientDB({
host: 'localhost',
port: 2424,
username: 'root',
password: 'root'
});
var db = server.use({
name: 'GratefulDeadConcerts',
username: 'root',
password: 'root'
});
server.close();
UPDATE
var OrientDB = require('orientjs');
var server = OrientDB({
host: 'localhost',
port: 2424,
username: 'root',
password: 'root'
}).use({
name: 'GratefulDeadConcerts',
username: 'root',
password: 'root'
});
server.close();
Hope it helps
Related
I am building a platform that offers different applications, the main platform is running on http://localhost and the applications will run each on a specific subdomain, at the moment I have an application running on http://sub.localhost.
I am using Nginx and Docker to host both the platform and the application, my goal would be to authenticate on http://localhost and use the session of the platform in the applications (subdomains), I have already taken a look at every single source/similar problem but could not find a solution, some of the sources I have read are the following:
https://github.com/nextauthjs/next-auth/discussions/1299
https://github.com/nextauthjs/next-auth/issues/405
https://github.com/nextauthjs/next-auth/issues/2718
At the moment this is my .env.local on the main platform:
NODE_ENV=development
GOOGLE_CLIENT_ID=...
GOOGLE_CLIENT_SECRET=...
GOOGLE_AUTH_URL=...
NEXTAUTH_URL=http://localhost/
NEXTAUTH_URL_INTERNAL=http://mygames:3000/
NEXTAUTH_SECRET=...
DATABASE_URL=...
NEXT_PUBLIC_API_KEY=...
NEXT_SECRET_API_KEY=...
The following is the .env.local of the application (subdomain):
NEXTAUTH_URL=http://sub.localhost/
NEXTAUTH_URL_INTERNAL=http://mygames:3000/
NEXTAUTH_SECRET=...
DATABASE_URL=...
NEXT_PUBLIC_API_KEY=...
NEXT_SECRET_API_KEY=...
The following is my [...nextauth].js for the main platform:
import NextAuth from 'next-auth';
import GoogleProvider from 'next-auth/providers/google';
import { PrismaAdapter } from '#next-auth/prisma-adapter';
import prisma from '../../../lib/prisma';
import Stripe from 'stripe';
const getDomainWithoutSubdomain = url => {
const urlParts = new URL(url).hostname.split('.');
return urlParts
.slice(0)
.slice(-(urlParts.length === 4 ? 3 : 2))
.join('.');
};
const hostName = getDomainWithoutSubdomain(process.env.NEXTAUTH_URL);
console.log("HOSTNAME", hostName);
const options = {
secret: process.env.NEXTAUTH_SECRET,
adapter: PrismaAdapter(prisma),
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
],
pages: {
signIn: '/signin'
},
callbacks: {
async signIn({ user, account, profile, email, credentials }) {
return true;
},
async redirect({ url, baseUrl }) {
return baseUrl;
},
async session({ session, user, token }) {
return { ...session, ...user };
},
async jwt({ token, user, account, profile, isNewUser }) {
return token;
}
},
cookies: {
sessionToken: {
name: process.env.NODE_ENV === 'production' ? `__Secure-next-auth.session-token` : 'next-auth.session-token',
options: {
httpOnly: true,
sameSite: 'lax',
path: '/',
secure: process.env.NODE_ENV === 'production' ? true: false,
domain: '.' + hostName
}
}
}
}
export default (req, res) => NextAuth(req, res, options)
When I use getSession in the subdomain application I receive a null object, what can I do to solve this? Feel free to ask for anything for more details!
Spent ages looking for a solution...
Solution:
https://github.com/nextauthjs/next-auth/discussions/4089#discussioncomment-2290660
TLDR; You cannot use localhost subdomains as intended. You must use example.com and app.example.com. To set these go to the hosts file in you system.
Follow the steps in the github post if needed
System Information
Strapi Version: 4.2.0-beta.2
Operating System: Mac OS Monterey
Node Version: v16.14.2
NPM Version: 8.5.4
Hello everybody,
Does anyone know how to set the APP_KEYS asynchronously?
My code is:
// index.ts
export default {
async register({ strapi }) {
const credentials = await getAwsSecrets();
strapi.config.set("server", {
host: credentials.HOST,
port: credentials.PORT,
app: {
keys: credentials.APP_KEYS,
},
});
}
}
// server.ts
export default ({ env }) => ({
host: env("HOST", "0.0.0.0"),
port: env.int("PORT", 1337),
app: {
keys: env.array("APP_KEYS"),
},
});
But this error is occurs:
debug: ⛔️ Server wasn't able to start properly.
error: Middleware "strapi::session": App keys are required. Please set app.keys in config/server.js (ex: keys: ['myKeyA', 'myKeyB'])
at instantiateMiddleware (node_modules/#strapi/strapi/lib/services/server/middleware.js:12:11)
at resolveMiddlewares (node_modules/#strapi/strapi/lib/services/server/middleware.js:56:18)
at registerApplicationMiddlewares (node_modules/#strapi/strapi/lib/services/server/register-middlewares.js:66:29)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Object.initMiddlewares (node_modules/#strapi/strapi/lib/services/server/index.js:99:7)
at async Strapi.bootstrap (node_modules/#strapi/strapi/lib/Strapi.js:436:5)
at async Strapi.load (node_modules/#strapi/strapi/lib/Strapi.js:448:5)
at async Strapi.start (node_modules/#strapi/strapi/lib/Strapi.js:196:9)
I have problem regarding on my authentication after I login there is prompt localhost:8000 login or Sign in, this is the first time I encounter this, I don't know what this called, i don't find any reference for this. currently I am using laravel for the backend and vue js for front end. so this project created by old developer. so now I need to revise some module on there project, however i Login on the system in shows this prompt. note that this project is currently working and there is no error and prompt login when I login.
Here is prompt sign shown after I login.
Configuration:
Laravel Passport
Vuex For State Management
Vue Js
METHOD:
methods:{
authenticate(){
this.login_alert = false
this.$validator.validateAll().then((result)=>{
if(result){
const self = this;
const authUser = {}
try{
const data = {
username: this.email,
password: this.password,
remember: this.remember_me,
client_id: '2',
client_secret: 'just secret only',
grant_type : 'password',
scope : ''
}
this.$store.dispatch('AUTH_REQUEST',data)
.then(response=>{
authUser.access_token = response.access_token
authUser.refresh_token = response.refresh_token
authUser.expires_in = response.expires_in
window.localStorage.setItem('project_token',JSON.stringify(authUser))
/*LOGIN*/
this.login_alert = false
this.loading = false
window.location.reload()
})
.catch(error=>{
this.login_alert = true
window.localStorage.removeItem('project_token')
this.loading = false
})
}catch(err){
console.log(err);
}
}
})
}
},
AUTH REQUEST:
AUTH_REQUEST:({commit,dispatch},obj)=>{
return new Promise((resolve,reject) => {
axios({
url: '/oauth/token',
data: obj,
method:'post',
config:'JSON'
})
.then(response=>{
if(response.status == 200){
resolve(response.data);
}
})
.catch(error=>{
reject(error);
localStorage.removeItem('project_token');
commit('AUTH_ERROR',error);
})
})
},
Hope someone can help me to solve this problem.
Thank you.
I'm trying to switch out express-graphql to apollo-server v2 but I'm having difficult time migrating packages, especially with passportjs and session.
My current set up with express-graphql:
const schema = include('schema')
const app = express()
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(session({
secret: process.env.SESSION_SECRET,
name: 'sessionId',
resave: false,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection }),
}))
app.use(passport.initialize())
app.use(passport.session())
app.use('/graphql', expressGraphQL({ schema }))
const server = http.createServer(app)
server.listen(8000, '0.0.0.0', () =>
console.log('Server running on port 8000')
)
And now with apollo-server-express#rc:
const schema = include('schema')
const app = express()
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(session({
secret: process.env.SESSION_SECRET,
name: 'sessionId',
resave: false,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection }),
}))
app.use(passport.initialize())
app.use(passport.session())
const apollo = new ApolloServer({
schema,
context: ({ req: { user, session } }) => ({ user, session })
})
apollo.applyMiddleware({ app, path: '/graphql' })
server.listen(8000, '0.0.0.0', () =>
console.log('Server running on port 8000')
)
With this, I'm getting user and session objects in context and works like before but when I try to login() or logout() users via context it says login is not a function.
Ok so in context, context: ({ req: { user, session, login, logout } }) => ({ user, session, login, logout }) and try again, but now I'm getting Passport is not initialized
Before I didn't have to set context with express-graphql so that's where I'm stuck. Please help?
I am building a react (ES6) application with Webpack in SailsJS.
The problem I came across is that session is not properly handled or stored in Local Memory Store IF the action is triggered from the frontend
Setup:
// TestAPIController:
module.exports = {
create: function(req, res){
// TODO: Add user authentication piece
var user = {name: 'test user'};
req.session.user = user.name;
req.session.authenticated = true;
console.log('session:', req.session);
// req.session.save();
res.json(req.session);
},
echo: function(req, res){
console.log('session:', req.session);
return res.json({message:'got it'});
}
};
Policy:
TestAPIController: {
echo : 'sessionAuth'
}
Route:
'GET /TestAPI/create' : {
controller: 'TestAPIController',
action:'create'
},
'GET /TestAPI/echo' : {
controller: 'TestAPIController',
action:'echo'
},
Front End
onClickCreate(e){
fetch('/TestAPI/create').then( res => res.json());
}
onClickEcho(e){
fetch('/TestAPI/echo').then(res => res.json());
}
MarkUp
<li><a onClick={_this.onClickCreate}>Create Test</a></li>
<li><a onClick={_this.onClickEcho}>Echo Test</a></li>
Senario A
Click on Create Console Log: [CORRECT!]
Requested :: GET /TestAPI/create
session: Session {
cookie:
{ path: '/',
_expires: 2017-01-18T20:21:01.069Z,
originalMaxAge: 86400000,
httpOnly: true },
user: 'test user',
authenticated: true }
And Then click on Echo, Console Log: [WRONG!]
Requested :: GET /TestAPI/echo
verbose: Sending 403 ("Forbidden") response:
You are not permitted to perform this action.
Senario B
Now go to http://localhost:3000/TestAPI/create in the chrome browser's URL
Browser prints the return from the call. and Log:
Requested :: GET /TestAPI/create
session: Session {
cookie:
{ path: '/',
_expires: 2017-01-18T20:21:13.645Z,
originalMaxAge: 86400000,
httpOnly: true },
user: 'test user',
authenticated: true }
And then enter http://localhost:3000/TestAPI/echo in url address
Browser prints the return from the call [CORRECT!]
Requested :: GET /TestAPI/echo
session: Session {
cookie:
{ path: '/',
_expires: 2017-01-18T20:25:24.019Z,
originalMaxAge: 86400000,
httpOnly: true },
user: 'test user',
authenticated: true }
Maybe there is some fundamental principle I'm not following?
Or maybe there is a better way to control sessions?
Any help would be appreciated.
You have the solution here guys: https://github.com/balderdashy/sails/issues/3965