Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dashboard PV278
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Polaško
Dashboard PV278
Commits
ae7efd3e
There was an error fetching the commit references. Please try again later.
Commit
ae7efd3e
authored
4 years ago
by
Karel Hala
Browse files
Options
Downloads
Patches
Plain Diff
Add JSdoc to custom functions
parent
81567979
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/react-auth0-spa.js
+8
-3
8 additions, 3 deletions
src/react-auth0-spa.js
src/utils/api.js
+14
-1
14 additions, 1 deletion
src/utils/api.js
with
22 additions
and
4 deletions
src/react-auth0-spa.js
+
8
−
3
View file @
ae7efd3e
...
@@ -65,6 +65,13 @@ export const Auth0Provider = ({ children, onRedirectCallback = DEFAULT_REDIRECT_
...
@@ -65,6 +65,13 @@ export const Auth0Provider = ({ children, onRedirectCallback = DEFAULT_REDIRECT_
setUser
(
user
);
setUser
(
user
);
};
};
/**
* Update user data in Auth0 application.
* @param {*} userData data to be updated.
* @example
* updateProfile({ user_metadata: { name: "something" } }) // updates user metadata
* @see https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id
*/
const
updateProfile
=
async
(
userData
)
=>
{
const
updateProfile
=
async
(
userData
)
=>
{
if
(
isAuthenticated
)
{
if
(
isAuthenticated
)
{
const
[{
_id
,
...
body
}]
=
await
Api
.
get
(
"
/rest/auth
"
);
const
[{
_id
,
...
body
}]
=
await
Api
.
get
(
"
/rest/auth
"
);
...
@@ -75,15 +82,13 @@ export const Auth0Provider = ({ children, onRedirectCallback = DEFAULT_REDIRECT_
...
@@ -75,15 +82,13 @@ export const Auth0Provider = ({ children, onRedirectCallback = DEFAULT_REDIRECT_
body
:
JSON
.
stringify
(
body
)
body
:
JSON
.
stringify
(
body
)
})
})
).
json
();
).
json
();
const
rawUserData
=
await
(
return
(
await
fetch
(
`https://
${
domain
}
/api/v2/users/
${
user
.
sub
}
`
,
{
await
fetch
(
`https://
${
domain
}
/api/v2/users/
${
user
.
sub
}
`
,
{
method
:
"
PATCH
"
,
method
:
"
PATCH
"
,
headers
:
{
Authorization
:
`Bearer
${
access_token
}
`
,
"
Content-Type
"
:
"
application/json
"
},
headers
:
{
Authorization
:
`Bearer
${
access_token
}
`
,
"
Content-Type
"
:
"
application/json
"
},
body
:
JSON
.
stringify
(
userData
)
body
:
JSON
.
stringify
(
userData
)
})
})
).
json
();
).
json
();
setUser
(
rawUserData
);
return
rawUserData
;
}
}
};
};
...
...
This diff is collapsed.
Click to expand it.
src/utils/api.js
+
14
−
1
View file @
ae7efd3e
...
@@ -4,6 +4,15 @@ import get from "lodash/get";
...
@@ -4,6 +4,15 @@ import get from "lodash/get";
import
config
from
"
../auth_config.json
"
;
import
config
from
"
../auth_config.json
"
;
import
keys
from
"
../api_keys.json
"
;
import
keys
from
"
../api_keys.json
"
;
/**
* Update or add data at given path in custom data.
* @param {string} path what should be updated, requires at least team.dataset.
* @param {object} payload data payload that'll be saved on path.
* @param {add|replace} method either add or replace.
* @example:
* API.updateData("professors.example", {some: "value"}) // merging with previous data
* API.updateData("professors.example", {different: "value"}, "replace") // rewriting data
*/
const
updateData
=
(
api
)
=>
(
path
,
payload
,
method
=
"
add
"
)
=>
{
const
updateData
=
(
api
)
=>
(
path
,
payload
,
method
=
"
add
"
)
=>
{
if
(
!
path
)
{
if
(
!
path
)
{
throw
new
Error
(
"
Error, path must be specified when calling updateData endpoint
"
);
throw
new
Error
(
"
Error, path must be specified when calling updateData endpoint
"
);
...
@@ -30,8 +39,12 @@ const updateData = (api) => (path, payload, method = "add") => {
...
@@ -30,8 +39,12 @@ const updateData = (api) => (path, payload, method = "add") => {
});
});
};
};
/**
* Retrieve custom data for specific team.
* @param {string} teamName team to read data from.
*/
const
getCustomData
=
(
api
)
=>
(
teamName
=
"
professors
"
)
=>
{
const
getCustomData
=
(
api
)
=>
(
teamName
=
"
professors
"
)
=>
{
return
api
.
get
(
`/rest/customdata?q={
"team": "
${
teamName
}
"
}`
);
return
api
.
get
(
`/rest/customdata?q={"team": "
${
teamName
}
"}`
);
};
};
const
instances
=
Object
.
entries
(
keys
).
reduce
(
const
instances
=
Object
.
entries
(
keys
).
reduce
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment