Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dexie Cloud: Allow DB owners impersonate users. #1866

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/dexie-cloud/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dexie-cloud-addon",
"version": "4.0.1-beta.54",
"version": "4.0.1-beta.55",
"description": "Dexie addon that syncs with to Dexie Cloud",
"main": "dist/umd/dexie-cloud-addon.js",
"type": "module",
Expand Down
23 changes: 22 additions & 1 deletion addons/dexie-cloud/src/authentication/interactWithUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,28 @@ export async function promptForEmail(
emailHint?: string
) {
let email = emailHint || '';
while (!email || !/^[\w-+.]+@([\w-]+\.)+[\w-]{2,10}$/.test(email)) {
// Regular expression for email validation
// ^[\w-+.]+@([\w-]+\.)+[\w-]{2,10}(\sas\s[\w-+.]+@([\w-]+\.)+[\w-]{2,10})?$
//
// ^[\w-+.]+ : Matches the start of the string. Allows one or more word characters
// (a-z, A-Z, 0-9, and underscore), hyphen, plus, or dot.
//
// @ : Matches the @ symbol.
// ([\w-]+\.)+ : Matches one or more word characters or hyphens followed by a dot.
// The plus sign outside the parentheses means this pattern can repeat one or more times,
// allowing for subdomains.
// [\w-]{2,10} : Matches between 2 and 10 word characters or hyphens. This is typically for
// the domain extension like .com, .net, etc.
// (\sas\s[\w-+.]+@([\w-]+\.)+[\w-]{2,10})?$ : This part is optional (due to the ? at the end).
// If present, it matches " as " followed by another valid email address. This allows for the
// input to be either a single email address or two email addresses separated by " as ".
//
// The use case for "<email1> as <email2>"" is for when a database owner with full access to the
// database needs to impersonate another user in the database in order to troubleshoot. This
// format will only be possible to use when email1 is the owner of an API client with GLOBAL_READ
// and GLOBAL_WRITE permissions on the database. The email will be checked on the server before
// allowing it and giving out a token for email2, using the OTP sent to email1.
while (!email || !/^[\w-+.]+@([\w-]+\.)+[\w-]{2,10}(\sas\s[\w-+.]+@([\w-]+\.)+[\w-]{2,10})?$/.test(email)) {
email = (
await interactWithUser(userInteraction, {
type: 'email',
Expand Down