Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export async function authorizeClient(urbitAddress, urbitCode) {
- return new Promise(async (resolve, reject) => {
- try {
- const headers = { "Content-Type": "application/x-www-form-urlencoded" }
- const res = await http.request({
- url: `${urbitAddress}/~/login`,
- method: 'POST',
- content: `password=${urbitCode}`,
- headers,
- })
- if(res.statusCode === 200) {
- const cookieHeader = res.headers['set-cookie']
- resolve(cookieHeader.split(';')[0])
- } else {
- reject('Authorization failed.')
- }
- } catch (ex) {
- console.log(ex.stack)
- reject(ex)
- }
- })
- }
- export async function verifyServer(urbitAddress) {
- return new Promise(async (resolve) => {
- try {
- const res = await http.request({
- url: `${urbitAddress}/~/login`,
- method: 'GET',
- })
- if(res.statusCode === 200) {
- resolve(true)
- } else {
- resolve(false)
- }
- } catch (ex) {
- console.log(ex.stack)
- resolve(false)
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement