-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add better docs for setting the user (#12224)
--------- Co-authored-by: Charly Gomez <[email protected]> Co-authored-by: Alex Krawiec <[email protected]>
- Loading branch information
1 parent
00e7000
commit 47a010b
Showing
6 changed files
with
96 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
platform-includes/enriching-events/set-user-middleware/javascript.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
```javascript | ||
// Add a middleware, for example: | ||
app.use((req, res, next) => { | ||
// Get the user from somewhere | ||
const user = req.user; | ||
|
||
// Set the user data for all requests | ||
if (user) { | ||
Sentry.setUser({ | ||
id: user.id, | ||
email: user.email, | ||
username: user.username, | ||
}); | ||
} else { | ||
Sentry.setUser(null); | ||
} | ||
|
||
next(); | ||
}); | ||
``` |
22 changes: 22 additions & 0 deletions
22
platform-includes/enriching-events/set-user-middleware/javascript.node.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
```javascript | ||
const Sentry = require("@sentry/node"); | ||
|
||
// Add a middleware, for example: | ||
app.use((req, res, next) => { | ||
// Get the user from somewhere | ||
const user = req.user; | ||
|
||
// Set the user data for all requests | ||
if (user) { | ||
Sentry.setUser({ | ||
id: user.id, | ||
email: user.email, | ||
username: user.username, | ||
}); | ||
} else { | ||
Sentry.setUser(null); | ||
} | ||
|
||
next(); | ||
}); | ||
``` |
16 changes: 16 additions & 0 deletions
16
platform-includes/enriching-events/set-user-request/javascript.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
```javascript | ||
// Your route handler, for example: | ||
app.get("/my-route", (req, res) => { | ||
// Get the user from somewhere | ||
const user = req.user; | ||
|
||
// Set the user data for this request only | ||
Sentry.setUser({ | ||
id: user.id, | ||
email: user.email, | ||
username: user.username, | ||
}); | ||
|
||
res.send("Hello World"); | ||
}); | ||
``` |
18 changes: 18 additions & 0 deletions
18
platform-includes/enriching-events/set-user-request/javascript.node.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
```javascript | ||
const Sentry = require("@sentry/node"); | ||
|
||
// Your route handler, for example: | ||
app.get("/my-route", (req, res) => { | ||
// Get the user from somewhere | ||
const user = req.user; | ||
|
||
// Set the user data for this request only | ||
Sentry.setUser({ | ||
id: user.id, | ||
email: user.email, | ||
username: user.username, | ||
}); | ||
|
||
res.send("Hello World"); | ||
}); | ||
``` |
5 changes: 5 additions & 0 deletions
5
platform-includes/enriching-events/set-user/javascript.node.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
```javascript | ||
const Sentry = require("@sentry/node"); | ||
|
||
Sentry.setUser({ email: "[email protected]" }); | ||
``` |