For some applications my team creates authenticated users with a password/email combination. This will get the user an firebase user uid. The problem with this is that the keys in firebase itself are external id's, and they do not match the auth.uid. How would I go about creating security rules then?
Sample auth.uid:
9dkad6c7-s649-9623-99e2-5a0dbgf5dfdz
Then a sample of the structure:
database
|
—— conversations
|
——{external id 1}
| |
| ——{external id 2}
| |
| {data here}
|
messages
|
——{externalid1|externalid2}
| |
| —{-KFasdahsduids}
| |
| {data here}
|
|
users
|
——{externalId}
| |
| {first name}
| {last name}
| {firebaseUID}
| {more data here}
|
——{externalId2}
|
{first name}
{lastname}
{firebaseUID}
{more data here}
The problem really is that the auth.uid is not the same as the external ones, and we really need those external id's. Can I do something with the UID that is stored in the /users/? Any suggestions?
Related
I'm working on a dating app. Right now we don't want to show the data of users that users have already seen.
For example, let's suppose if A has seen B and C.
now we want to show more users to A. Then B and C should be excluded from that list.
What I'm doing is getting data from firebase like [B, C, D, E, F] as B, C is already seen. So removing those we have [D, E, F].
What's the issue:
Actually getting the same data, again and again, makes more reading numbers. It also slows down the getting of data process. Like if we get a list from firebase and all the profiles in that list are already seen then the device again sends a request to firebase and gets more profiles. it does the same for the new list and if these are also seen so it makes another request again. This takes time and users have to wait until there are profiles to swipe.
Can we make something like that? We just save a list of all the seen profiles at any point and make a rule to exclude those profiles from the search result.
We don't need those profiles at one point but we need to access those profiles to show user he has seen these profiles.
Any help will be appreciated.
I got a little similar case but I didn’t understand
{
"rules": {
"Children": {
"$child_id": {
".read": "auth != null &&
root.child('Family').child(
root.child('User').child(
data.child('parentId').val()
).val()
).child('members').child(auth.uid).exists()
}
}
}
}
Update:
there are different node:
database
|
`- users
| |
| `- userId
| | |
| | `-name
| | `-id
| | `-address
| | `-..... more details
| `- userId
| | |
| | `-name
| | `-id
| | `-address
| | `-..... more details
| |
| `- more users . .
|
`- swipes
| |
| `- uniqueId
| | |
| | `- whoSwiped: id
| | `- whoIsSwiped: id
| | `- swipedType: like/dislike
| | `- createdAt: date
| `- uniqueId
| |
| `- whoSwiped: id
| `- whoIsSwiped: id
| `- swipedType: like/dislike
| `- createdAt: date
first swiped id is fetched then user from "users" node is fetched ids that are already swiped are removed from the users' list.
I have a DB with users and items.
Every user has languages, which is an array of languages, for example ['en', 'ar']
Every item has language, which is a string, for example 'en'.
How can I index my items, such that I can get a list of the last X items in an array of languages? (i.e - latest 5 items who are either 'en' or 'ar')
For a single language the solution is simple - have an index that has the language key, and array of item keys ordered by whatever.
Please note that the Firebase official documentation recommends against using arrays. IMHO, the main problem in your project is that you trying to use an array, which is an anti-pattern when it comes to Firebase. Beside that, one of the many reasons Firebase recommends against using arrays is that it makes the security rules impossible to write. Because a Firebase database is structured as pairs of key and values, the best option is to use a Map.
To achieve what you want, i recomand you using a database structure which looks like this:
Firebase-root
|
--- users
| |
| --- UID1
| | |
| | --- languages
| | |
| | --- languageId1: true
| | |
| | --- languageId2: true
| |
| --- UID2
| |
| --- languages
| |
| --- languageId3: true
| |
| --- languageId4: true
|
--- languages
| |
| --- languageId1
| | |
| | --- languageName: "en"
| | |
| | --- items
| | |
| | --- itemId1: true
| |
| --- languageId2: "ar"
| | |
| | --- languageName: "ar"
| | |
| | --- items
| | |
| | --- itemId2: true
|
--- item
|
--- itemId1
| |
| --- title: "ItemTitleEn"
| |
| --- en: true
|
--- itemId2
|
--- title: "ItemTitleAr"
|
--- ar: true
Now, with this database structure you can achieve everything you want. For example, you can query your database to display all languages from you database. You can also display all the languages of a single user.
If you want to query your database for the last x item which have the language set to en, you just need to put a listener on the items node and create a query using functions like: orderByChild(), equalsTo() and limitToLast(). Such a query should look like this:
query = rootRef.child("items")
.orderByChild("en")
.equalsTo(true)
.limitToLast(5)
.addListener(/* ... */)
EDIT: Unfortunately Firebase does not allow multiple conditions in a query. So in Firebase there is no where clause that sounds like this: WHERE language = "en" AND language = "ar". So to solve this, you need to put a listener on the other node, on languages node.
The flow is as follows:
yourRef = rootRef.child("languages"); //only one listener
yourRef.addListener(
1. Create a list
2. get items from dataSnapshot.child("languageId1").child("items").getChildren()
3. add **en** items to the list
4. get items from dataSnapshot.child("languageId2").child("items").getChildren()
5. add **ar** items to the list
6. display the list that contains data from both languages
)
Hope it helps.
I'm starting with Docker and in my opinion is great! Now I'm looking solution for this organization:
Now I have this structure:
Applications
| +--app1
| | +--node_modules
| | +--package.json
| | +--...
| +--app2
| | +--node_modules
| | +--package.json
| | +--...
| ....
| docker-compose.app1.yml
| docker-compose.app2.yml
| ....
| Dockerfile //my personalized image for all projects
But I want reach this:
Applications
| +--app1
| | +--node_modules //empty in host
| | +--package.json
| | +--docker-compose.app1.yml //override compose
| | +--...
| +--app2
| | +--node_modules //empty in host
| | +--package.json
| | +--...
| ....
| +--node_modules //global node_modules folder (linked to projects)
| docker-compose.yml //principal compose
| Dockerfile //my personalized image for all projects
I thinking too about create one global "server" and link all projects on VHosts but how I'll get access to each of project?
You are looking for docker-comopose extends. Thas permits you override previus configurations.
web:
extends: file: common-services.yml
service: webapp
See full documentation in : https://docs.docker.com/compose/extends/#extending-services
How do I determine what the SQL statement is of the thread ID showing up in a metadata lock info row (SELECT * FROM information_schema.metadata_lock_info) on MariaDB?
Server version: 10.0.15-MariaDB MariaDB Server
All of the related questions dive into the "Waiting for table metadata lock" from a MySQL perspective, but that does not help with MariaDB since their introspection is implemented differently from what I can tell. Googling around does not turn up a whole lot.
A "show full processlist" gives rows like:
| 57295 | main | localhost | joints | Execute | 50 | Waiting for table metadata lock | select ...
Which does show the statement, but does not show that it has the lock either. So, I turned on metadata lock info as explained here [0]. This only provides the thread ID of the lock holder, but not the statement:
MariaDB [joints]> SELECT * FROM information_schema.metadata_lock_info;
+-----------+--------------------------+-----------------+----------------------+--------------+----------------+
| THREAD_ID | LOCK_MODE | LOCK_DURATION | LOCK_TYPE | TABLE_SCHEMA | TABLE_NAME |
+-----------+--------------------------+-----------------+----------------------+--------------+----------------+
| 57322 | MDL_INTENTION_EXCLUSIVE | MDL_EXPLICIT | Global read lock | | |
| 57322 | MDL_SHARED_NO_READ_WRITE | MDL_EXPLICIT | Table metadata lock | joints | 16_study |
| 57322 | MDL_INTENTION_EXCLUSIVE | MDL_EXPLICIT | Schema metadata lock | joints | |
| 57269 | MDL_SHARED_READ | MDL_TRANSACTION | Table metadata lock | joints | authentication |
| 57301 | MDL_SHARED_READ | MDL_TRANSACTION | Table metadata lock | joints | authentication |
| 57280 | MDL_SHARED_READ | MDL_TRANSACTION | Table metadata lock | joints | authentication |
| 57317 | MDL_SHARED_READ | MDL_TRANSACTION | Table metadata lock | joints | ship |
| 57271 | MDL_SHARED_READ | MDL_TRANSACTION | Table metadata lock | joints | administration |
| 57264 | MDL_SHARED_READ | MDL_TRANSACTION | Table metadata lock | joints | server |
+-----------+--------------------------+-----------------+----------------------+--------------+----------------+
What I really want is to see the "join" of both of those outputs at the moment the locking is happening. I do not see a way to join the data from these two "tables" since the former does not appear to be a table. I'd like to avoid getting:
ERROR 1933 (HY000): Target is not running an EXPLAINable command
while attempting to do it in real-time, due to the thread ending while being inspected.
[0] https://mariadb.com/kb/en/mariadb/metadata_lock_info/
THREAD_ID maps to information_schema.PROCESSLIST.ID (the first column in show
[full] processlist;. ie:
SELECT * FROM information_schema.METADATA_LOCK_INFO AS mli
JOIN information_schema.PROCESSLIST AS pl ON mli.THREAD_ID = pl.ID
I am preferential towards something like the following to make it easier to see the what is happening (the newlines don't work well with the cli though):
SELECT
mli.THREAD_ID, mli.LOCK_MODE, mli.LOCK_TYPE,
CAST(GROUP_CONCAT(DISTINCT CONCAT(mli.TABLE_SCHEMA, '.', mli.TABLE_NAME) ORDER BY mli.TABLE_SCHEMA, mli.TABLE_NAME SEPARATOR '\n') AS CHAR) AS locked_tables,
pl.USER, pl.HOST, pl.DB, pl.COMMAND, pl.TIME, pl.STATE, pl.INFO, pl.QUERY_ID, pl.TID
FROM information_schema.METADATA_LOCK_INFO AS mli
JOIN information_schema.PROCESSLIST AS pl ON mli.THREAD_ID = pl.ID
GROUP BY mli.THREAD_ID, mli.LOCK_MODE, mli.LOCK_TYPE
ORDER BY time DESC, pl.ID;
Especially interesting is when pl.COMMAND = 'Sleep' as that indicates some connection pool or other (mostly read-only) program is holding open connections that have locks on them.
I have two bundles and I want routes from one of the bundle only accessible if the user have a defined role.
The logic from the router matcher should be:
if the user have the role
| name | path | success |
|------------------|-------|---------|
| bundle_1_route_1 | / | false |
| bundle_1_route_2 | /test | true |
If the user don't have the role
| name | path | success |
|------------------|-------|---------|
| bundle_1_route_1 | / | false |
| bundle_1_route_2 | /test | false |
| bundle_2_route_1 | /aaa | false |
| bundle_2_route_2 | /test | true |
The problem is I can't do that using the security because the path are the same
I tried with the #security annotation http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html
But I have an access denied when on bundle_1_route_2 with no role and the others urls are not checked.
I want to continue checking all the available url if the role is not matching
I found an other solution, but this is not very clean, and it will create error if the session does not exists
bundle_1:
resource: "#Bundle1/Controller/"
type: annotation
prefix: /
condition: "'ROLE_FILTER' in request.getSession().get('bundle1.user').getRoles()"
Is there a way to create completely custom conditions on routing ?