GithubHelp home page GithubHelp logo

Comments (3)

lopugit avatar lopugit commented on June 28, 2024

The only way is to rethink the way you do data storage using encryption and permission Middleware

from minimongo.

yanickrochon avatar yanickrochon commented on June 28, 2024

Or you can provide your own httpClient passing CORS options like credentials: 'include', then implement session-based HTTP proxy to your database.

from minimongo.

FROGGS avatar FROGGS commented on June 28, 2024

This entire project is client side code. You cannot trust anything happening here, so this is not just about exposing an url or connection id. (I wonder how you do want to hide anything browser related to a user)

What I did is implement proper security (authentication via JWT basically and authorisation on collections and their methods) on the server side. That is the service hosting the API minimongo is talking to.

Then, because I'm using Angular, I hat to write a tiny wrapper so minimongo is using my httpClient, which is configured to send cookies to the api-server.

My client sode code looks somewhat like this, though I additionally have an interceptor that sets the withCredentials options for every outgoing http request to my backends.

import * as minimongo from 'minimongo';

// This is just a loggin helper to get started.
const log = (name: string) => ((...args: any[]) => console.log(name, args));

// Setup local, remote and hybrid database
const IndexedDb = new minimongo.IndexedDb({}, log('IndexedDb success'), log('IndexedDb error'));
const RemoteDb  = new minimongo.RemoteDb('https://url.to.my.backend/api/');
const HybridDb  = new minimongo.HybridDb(IndexedDb, RemoteDb);

// My data service
@Injectable({
  providedIn: 'root'
})
export class FoobarDataService {
  constructor(
    private http: HttpClient,
  ) {
    // Mimic the interface that minimongo expects.
    const httpClient = (method: string, url: string, params: any, body: any, success: () => any, error: () => any) => {
      this.http.request(method, url, { body: body, params: params }).subscribe(success, error);
    };
    RemoteDb.httpClient = httpClient;
    IndexedDb.addCollection('foobar', log('IndexedDb.addCollection success'), log('IndexedDb.addCollection error'));
    RemoteDb.addCollection('foobar', {}, log('RemoteDb.addCollection success'), log('RemoteDb.addCollection error'));
    HybridDb.addCollection('foobar', log('HybridDb.addCollection success'), log('HybridDb.addCollection error'));
  }
}

from minimongo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.