Skip to content

Commit

Permalink
auth -> set initial accountId
Browse files Browse the repository at this point in the history
  • Loading branch information
wpdas committed Apr 17, 2023
1 parent 0907fc2 commit 66807c6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "near-social-bridge",
"version": "1.3.1",
"version": "1.3.2",
"description": "This library allows you to create a common application using ReactJS and inject it in a controlled way into a Widget on Near Social. Therefore, the Widget talks to the React application and vice versa, making it possible to consume Discovery API resources within the React application.",
"main": "./dist/cjs/index.js",
"module": "./index.js",
Expand Down
8 changes: 7 additions & 1 deletion src/auth/contexts/AuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import React, { createContext, useCallback, useEffect, useState } from 'react'
import { onConnectObservable, UserInfo } from '../../services/bridge-service'
import { getConnectionPayload, onConnectObservable, UserInfo } from '../../services/bridge-service'
import getUserInfo from '../getUserInfo'

type Auth = {
Expand Down Expand Up @@ -35,6 +35,12 @@ const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) =>

// Fetch user info
useEffect(() => {
// Set the initial user info
const preUserInfo = getConnectionPayload().userInfo
if (preUserInfo) {
setUser(preUserInfo)
}

const onConnectHandler = () => {
onConnectObservable.unsubscribe(onConnectHandler)
fetchUserInfo()
Expand Down
5 changes: 3 additions & 2 deletions widget/NearSocialBridgeCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ const getUserInfo = (requestType) => {
})
Utils.sendMessage(responseBody)
},
(err) => {
console.log('error fetching profile data', err)
() => {
// Send the accountId only
Utils.sendMessage({ accountId })
}
)
}
Expand Down

0 comments on commit 66807c6

Please sign in to comment.