lao8n / cnstlltn

MIT License
0 stars 0 forks source link

get some user_id to use for database writes and reads #21

Closed lao8n closed 6 months ago

lao8n commented 10 months ago

temporary solution is to hard-code the the user id as i'm unable to extract it the way i was hoping image when i've done this i'm able to successfully save to the cosmos db

https://stackoverflow.com/questions/77008575/azure-container-apps-login-flow i've written a stackoverflowquestion which hopefully someone can help me with

lao8n commented 6 months ago

public async getUserInfo(): Promise { try { const response = await axios.get('/.auth/me'); console.log("User info: ", response.data) return response.data; } catch (error) { console.error("Error getting user info: ", error); throw error } } this code doesn't help i get User info: <!doctype html>cnstlltn

lao8n commented 6 months ago

tried change the base url here public constructor(baseUrl: string) { this.client = axios.create(); this.baseUrl = baseUrl; }

public async getUserInfo(): Promise<any> {
    try {
        const response = await this.client.get(`${this.baseUrl}${/.auth/me}`);
        console.log("User info: ", response)
        return response.data;
    } catch (error) {
        console.error("Error getting user info: ", error);
        throw error
    }
}

public async saveSelectedFrameworks(userId: string, frameworks: QueryResponse[]): Promise<QueryResponse[]> {
    const response = await this.client.request<QueryResponse[]>({
        method: 'POST',
        url: `${this.baseUrl}/save-frameworks`,
        data: frameworks,
        headers: {'USER-ID': userId}
    });
    return response.data;
}

public async getConstellation(): Promise<UserFramework[]> {
    const response = await this.client.request<UserFramework[]>({
        method: 'GET',
        url: `${this.baseUrl}/get-constellation`,
    });
    return response.data;
}
lao8n commented 6 months ago

image

lao8n commented 6 months ago

image

lao8n commented 6 months ago

setting the box seems to solve the cors problem - maybe rather tahn definingi it in python app at a method level i should do it at a app level image

lao8n commented 6 months ago

what to do with this new error userService.ts:42

    GET https://ca-api-4a73yskoiju2e.whiteground-d98c7a61.eastus.azurecontainerapps.io/get-constellation net::ERR_NETWORK_CHANGED

(anonymous) @ InstrumentHooks.js:93 (anonymous) @ xhr.js:220 e.exports @ xhr.js:16 e.exports @ dispatchRequest.js:56 d.request @ Axios.js:109 (anonymous) @ bind.js:9 (anonymous) @ userService.ts:42 c @ regeneratorRuntime.js:44 (anonymous) @ regeneratorRuntime.js:125 (anonymous) @ regeneratorRuntime.js:69 Ke @ asyncToGenerator.js:3 a @ asyncToGenerator.js:22 (anonymous) @ asyncToGenerator.js:27 (anonymous) @ asyncToGenerator.js:19 (anonymous) @ userService.ts:47 (anonymous) @ userActions.ts:37 c @ regeneratorRuntime.js:44 (anonymous) @ regeneratorRuntime.js:125 (anonymous) @ regeneratorRuntime.js:69 Ke @ asyncToGenerator.js:3 a @ asyncToGenerator.js:22 (anonymous) @ asyncToGenerator.js:27 (anonymous) @ asyncToGenerator.js:19 (anonymous) @ userActions.ts:40 (anonymous) @ actionCreators.ts:45 c @ regeneratorRuntime.js:44 (anonymous) @ regeneratorRuntime.js:125 (anonymous) @ regeneratorRuntime.js:69 Ke @ asyncToGenerator.js:3 a @ asyncToGenerator.js:22 (anonymous) @ asyncToGenerator.js:27 (anonymous) @ asyncToGenerator.js:19 (anonymous) @ constellationPane.tsx:23 c @ regeneratorRuntime.js:44 (anonymous) @ regeneratorRuntime.js:125 (anonymous) @ regeneratorRuntime.js:69 Ke @ asyncToGenerator.js:3 a @ asyncToGenerator.js:22 (anonymous) @ asyncToGenerator.js:27 (anonymous) @ asyncToGenerator.js:19 (anonymous) @ constellationPane.tsx:22 (anonymous) @ constellationPane.tsx:33 Bu @ react-dom.production.min.js:262 t.unstable_runWithPriority @ scheduler.production.min.js:18 Go @ react-dom.production.min.js:122 Nu @ react-dom.production.min.js:261 (anonymous) @ react-dom.production.min.js:261 A @ scheduler.production.min.js:16 w.port1.onmessage @ scheduler.production.min.js:12 Show 41 more frames Show less

lao8n commented 6 months ago

now have no bugs - but containers apps doesn't include any docuemntation on using /.auth/me so i think you cannot therefore i need to find someother way

lao8n commented 6 months ago

completely change the way i'm trying to log in now <GoogleLogin onSuccess={handleLoginSuccess} onError={handleLoginFailure} />

lao8n commented 6 months ago

key was had to change the approach completely as you cannot use /.auth/me with azure containers const handleLoginSuccess = (response: CredentialResponse) => { console.log('Login Success:', response); // Extract the user information or token from the response // Dispatch action to update user state appContext.dispatch({ type: ActionTypes.SET_USER, isLoggedIn: true, userId: response.clientId || "", // Update based on actual response structure }); // Redirect to another page if needed navigate('/constellation'); };

const handleLoginFailure = () => { console.log('Login Failed'); };

useEffect(() => { const fetchGoogleClientId = async () => { const loginConfig = await actions.login.getLoginConfig() setGoogleClientId(loginConfig.googleClientId); }; fetchGoogleClientId(); });

return (

Login into cnstlltn