Getting URL parameters in VueJS after a page redirect has occurred

Currently, I am implementing a Login with Facebook feature in my VueJS application using a Third Party Service (AWS Cognito).

The process involves clicking on a "Login with Facebook" button which triggers a redirect to the third party URL where a Sign Up prompt is displayed for Facebook authentication.

For example:


window.location.href = https://my-cognito-app-domain/oauth2/authorize?response_type=token&client_id=my_client_id&redirect_uri=my_redirect_url&identity_provider=Facebook

Users input their Facebook login credentials to authenticate, and upon successful validation, they are redirected back to the VueJS application with an access_token appended as a URL parameter.

For instance: #access_token=eyJraWQiOiIyRHViM0VrY2 ...

The goal is to extract the access_token within the VueJS application context to perform further logic such as JWT decoding. However, attempts to retrieve the token using window.location.search in App.vue during creation or mounting have been unsuccessful due to the page redirection.

See below for a sample code snippet:


<template>
  <div id="app">

  </div>
</template>

<script type="text/javascript>
// @ is an alias to /src
import Navigation from '@/components/Navigation.vue'
import Footer from '@/components/Footer.vue'

export default {
  name: 'home',
  components: {
    Navigation,
    Footer
  },
  created(){
    console.log("created")
    var params = window.location.hash
    console.log(params)

  },
  mounted(){
      console.log("mounted")
      var params = window.location.hash
      console.log(params)
  }

}

The objective is to capture the access_token immediately after the redirection to the VueJS application. Is it correct to assume that App.vue is always reloaded post-redirection? If not, is there a method to monitor when the page gets redirected?

Answer №1

When you want to access the parameters of a URL, remember that <code>window.location.search
contains the information after the "?" sign.

If you are dealing with a redirect link that uses "#" instead of "?", then you should utilize window.location.hash, which holds the details following the "#" in the URL.

To learn more about these properties, visit: https://developer.mozilla.org/en-US/docs/Web/API/Location#Properties

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Despite adding app.use(flash()) to resolve the issue, the error 'TypeError: req.flash is not a function' persists

I encountered an error in my routes.js file: app.get('/login', function(req, res) { // Display the page and include any flash data if available res.render('login.html', { message: req.flash('loginMessage') }); }); ...

What is the process by which Elastic Beanstalk executes Node.js application code?

While my application runs smoothly on localhost, encountering no issues, deploying it to other platforms such as AWS or MCS presents a challenge. Specifically, the problem lies in recognizing the file paths required by the consign library to load the route ...

Ways to adjust the positioning of an image

Seeking assistance, I am currently working on building a portfolio using HTML while following a tutorial. I utilized undraw to insert an image but unfortunately, the image is fixed to the right-hand side: I would like to position the image below my icons, ...

creating an animated loop within an Angular template

How can we display a dynamic loop in Angular template using an array of object data? [ { "name": "name", "text": "text", "replies": [{ "name": "Reply1", "t ...

One particular item in the list does not conform to the same formatting as the others

Having a formatting issue with the indexLink when populating an unordered list with links. Can't seem to dedent it properly no matter what I try. Here's the javascript snippet: function addCrumb() { /* reads from localStorage and determines wh ...

When using Vimeo's JS API, the player.loadVideo() method will revert the player's settings back to their default options

Using Vimeo's player.js API, I'm setting options on the player to disable the title upon initialization: var options = { id: 59777392, title: false }; var vimPlayer = new Vimeo.Player('myDiv', options); The video player correc ...

Oops! There seems to be an issue with an invalid character in the literal true value while making a POST request to the API with JSON data. The expected character should be

Can anyone help me solve an issue I am facing while trying to use the POST method to insert data using JSON in JS code? When I attempt the transformation, I receive an error message stating: "ERROR: invalid character ' ' in literal true (e ...

Creating a JSON structure using an array in Typescript

Here is an example of my array structure: [ { "detail": "item1", "status": "active", "data": "item1_data" }, { "detail": "item2", "status": ...

Adapting the current codebase to be compatible with Typescript

Currently, my codebase is built with redux, redux-saga, and react using plain Javascript. We are now considering incorporating Typescript into the project. Some questions arise: Can plain Javascript files coexist with tsx code? I believe it's possibl ...

Integrating jQuery class into code snippets

I have implemented a fixed header on scroll by adding the class 'fixed' and it is working fine. When I scroll down, after 50px, the 'fixed' class is added to my header container. However, when I scroll back up, the 'fixed' cla ...

The data is not appearing in the Vuetify data table

I have encountered an issue with the Vuetify data table where it is not displaying any data. Even though it shows that there is 1 row out of 1 displayed, the table body remains empty. Below is my component code: <template> <v-data-table :hea ...

Creating GeoJson using JavaScript

Currently, I am retrieving a latitude/longitude array using Ajax $.ajax({ type: "POST", url: '../m/m_share.php', data: 'zone=' + zone, dataType: 'json', success: function(tab) { var i = 0; ...

Using Express and React with Socket.io

I am currently working on setting up a basic WebSocket connection using Socket.io, Express, and ReactJS. Below is the code for the server: const express = require('express'); const socket = require('socket.io'); const path = require(& ...

Is there a way to incorporate expandable content on a Drupal node page using Javascript?

Is there a Drupal Module available that can display a trimmed version of content on the node page and expand it when clicking on a "Read More" link? Thank you! ...

Hello there, could you please point out where the error is located in this code?

$(document).ready(function(){ $('#nav-b .navbar-item li a').click(function(){ $('#nav-b .navbar-item li a').removeClass('active'); $(this).addClass('active'); }); }); < ...

Progress of file uploads on the client side using Vue JS

I'm facing a challenge in creating a loading bar that shows the progress when a file is selected for upload in a form. Most of the examples I come across online demonstrate the loading bar after hitting an 'upload' button, but in my case, I ...

Utilizing Http to Retrieve JSON Data in Ionic 3

Struggling with Ionic, trying to fetch data from a JSON File using HTTP, but encountering a strange error. https://i.sstatic.net/L2nVo.png Below are the relevant code snippets : src/pages/subhome/line/line.ts (The Subhome consists of multiple nested pag ...

Experimenting with the testing of two distinct functions

Hello, I am new to the world of testing and I would appreciate some guidance. I have two functions that I need help with. The first function is a bits-per-second converter that converts data into a more readable format. const convertBitrate = bitrate =&g ...

Having trouble assigning more than one custom named property in TypeScript for MUI v5 Palette

I am currently setting up multiple custom attributes to make future updates easier. Nonetheless, I'm encountering a challenge with implementing more than one custom property in MUI v5. TypeScript Error TS2717: Subsequent property declarations must hav ...

What is the method of including a null option in a dropdown menu?

I have a basic dropdown menu with the placeholder text "none." I want users to be able to clear their selection without adding another option to the dropdown. Can anyone help me achieve this? Thank you! Below is my code snippet: Check out the live demo h ...