Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 1.13 KB

authentication.md

File metadata and controls

18 lines (14 loc) · 1.13 KB

Authentication

This is a simple walkthrough on handling user authentication using Pi SDK and API endpoint. For a detailed explanation, please refer to Pi.authenticate for SDK reference and /me for API reference.

Guide

Here is a list of steps you can follow when you authenticate users for your app:

1. Call authenticate() of Pi SDK

Using the Pi SDK authenticate(), you can obtain user information along with the access token.

const authRes = await window.Pi.authenticate(scopes, onIncompletePaymentFound);

2. Make a GET request to /me Pi API endpoint using the access token for verification

To verify the data you got in step 1, you need to make a GET request to /me Pi API endpoint, with the access token included in the header. If the access token is valid, it will return a response with UserDTO. However, if the token is invalid, it will return HTTP 401 Unauthorized code.

const me = await axios.get('https://api.minepi.com/v2/me', {headers: {'Authorization': `Bearer ${accessToken}}});