-
Notifications
You must be signed in to change notification settings - Fork 11
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
add trackVerifiedToken() #119
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<div class="content flex-grow-1 p-4"> | ||
<h1 class="mb-4">Track verified token</h1> | ||
<div id="error-alert" class="alert alert-danger fade show" role="alert" style="display: none;"> | ||
<strong>Error:</strong> <span id="error-text">Something went wrong. Check the developer console for details.</span> | ||
</div> | ||
|
||
<p>Use the Radar Verify app to verify the user's current location. Returns a JSON Web Token (JWT). Verify the JWT server-side using your secret key.</p> | ||
|
||
<div class="mt-5 mb-3 form-row"> | ||
<label for="user-id" class="col-form-label" style="width: 128px;">User ID</label> | ||
<div> | ||
<input type="text" class="form-control" id="user-id" value="test-user-id" style="width: 250px;"> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<button id="track-verified" type="button" class="btn btn-primary" disabled>Call track verified token</button> | ||
</div> | ||
|
||
<div id="loader" class="spinner-border text-primary mt-4" role="status" style="display: none;"> | ||
</div> | ||
|
||
<div id="response-details" style="display: none;"> | ||
<h6 class="mt-4">Token</h6> | ||
<div class="mt-2"> | ||
<pre style="white-space: pre-wrap"><code id="token" class="code-sample language-json"></code><pre> | ||
</div> | ||
</div> | ||
|
||
<div class="mt-4"> | ||
<pre><code class="code-sample language-html"><!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /> | ||
<link href="https://js.radar.com/v{{sdk_version}}/radar.css" rel="stylesheet"> | ||
<script src="https://js.radar.com/v{{sdk_version}}/radar.min.js"></script> | ||
</head> | ||
|
||
<body> | ||
<script> | ||
$('#track-verified').click(() => { | ||
Radar.initialize('<RADAR_PUBLISHABLE_KEY>'); | ||
|
||
Radar.trackVerifiedToken({ userId: 'test-user-id' }) | ||
.then(({ token }) => { | ||
console.log(token); | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html></code> | ||
</pre> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
$('#publishableKey').on('change', () => { | ||
const publishableKey = $('#publishableKey').val(); | ||
if (publishableKey) { | ||
$('#track-verified').prop('disabled', false); | ||
} | ||
}); | ||
|
||
$('#track-verified').click(() => { | ||
$('#error-alert').hide(); | ||
$('#response-details').hide(); | ||
|
||
const publishableKey = $('#publishableKey').val(); | ||
Radar.initialize(publishableKey, { debug: true }); | ||
|
||
$('#loader').show(); | ||
|
||
const userId = $('#user-id').val(); | ||
Radar.trackVerifiedToken({ userId }) | ||
.then(({ token }) => { | ||
console.log('TRACK RESPONSE', { token }); | ||
$('#loader').hide(); | ||
|
||
console.log(token); | ||
|
||
$('#response-details').show(); | ||
$('#token').html(token); | ||
hljs.highlightAll(); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
$('#loader').hide(); | ||
$('#error-alert').show(); | ||
$('#error-text').html(err.message); | ||
}); | ||
}); | ||
|
||
</script> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,10 @@ import Logger from '../logger'; | |
import Session from '../session'; | ||
import Storage from '../storage'; | ||
|
||
import type { RadarTrackParams, RadarTrackResponse } from '../types'; | ||
import type { RadarTrackParams, RadarTrackResponse, RadarTrackTokenResponse } from '../types'; | ||
|
||
class VerifyAPI { | ||
static async trackVerified(params: RadarTrackParams) { | ||
static async trackVerified(params: RadarTrackParams, encrypted: Boolean = false) { | ||
const options = Config.get(); | ||
|
||
// user indentification fields | ||
|
@@ -40,6 +40,7 @@ class VerifyAPI { | |
sdkVersion: SDK_VERSION, | ||
stopped: true, | ||
userId, | ||
encrypted, | ||
}; | ||
|
||
const response: any = await Http.request({ | ||
|
@@ -49,27 +50,39 @@ class VerifyAPI { | |
host: 'https://radar-verify.com:52516', | ||
}); | ||
|
||
const { user, events } = response; | ||
const { user, events, token } = response; | ||
let location; | ||
if (user.location && user.location.coordinates && user.locationAccuracy) { | ||
if (user && user.location && user.location.coordinates && user.locationAccuracy) { | ||
location = { | ||
latitude: user.location.coordinates[1], | ||
longitude: user.location.coordinates[0], | ||
accuracy: user.locationAccuracy, | ||
}; | ||
} | ||
|
||
const trackRes = { | ||
user, | ||
events, | ||
location, | ||
} as RadarTrackResponse; | ||
|
||
if (options.debug) { | ||
trackRes.response = response; | ||
if (encrypted) { | ||
const trackTokenRes = { | ||
token, | ||
} as RadarTrackTokenResponse; | ||
|
||
if (options.debug) { | ||
trackTokenRes.response = response; | ||
} | ||
|
||
return trackTokenRes; | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically don't need this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
const trackRes = { | ||
user, | ||
events, | ||
location, | ||
} as RadarTrackResponse; | ||
|
||
if (options.debug) { | ||
trackRes.response = response; | ||
} | ||
|
||
return trackRes; | ||
} | ||
|
||
return trackRes; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export default '4.1.3'; | ||
export default '4.1.4'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably omit the code samples on these. These should probably live in the docs (I only added them as a temporary solution until we go the UI kits in the docs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've actually found it helpful to be able to show the code sample when using this page in demos (which I'm doing a lot), but we can always remove later