When attempting to access the signup route, AngularJS automatically redirects to the signin route

Every time I launch my application, it redirects me to /signin automatically. However, when I attempt to access the /signup page, it fails to redirect. Is there a way to use next to direct to /signup when the path is http://localhost:9000/signup? Any suggestions?

user.service.js:

angular.module('crud').service('User', function($sails) {

  return {
    isLoggedIn: function() {

      this.getUser();

    },
    setUser: function(aUser) {
      localStorage.setItem('User', JSON.stringify(aUser));
    },

    getUser: function() {
      return localStorage.getItem('User');
      //console.log('retrievedObject: ', JSON.parse(retrievedObject));
    }
  }

});

APP.js:

.run(function($rootScope, $location, $log, User) {

      $rootScope.$on("$locationChangeStart", function(event, next, current, jwtHelper) {

        if (!User.isLoggedIn()) {
          $location.path("/signin");
        } else if (next === "http://localhost:9000/signup") {
          $location.path("/signup");
        }
      });

Answer №1

Whenever a user attempts to register, they are automatically redirected to the sign-in page. To prevent this interruption in routing to both the signup and signin pages, adjust the condition as follows:

.run(function($rootScope, $location, $log, User) {
      $rootScope.$on("$locationChangeStart", function(event, next, current, jwtHelper) {
        var allowed = ["http://localhost:9000/signup",
          "http://localhost:9000/signin"
        ]
        if (allowed.indexOf(next) < 0 && !User.isLoggedIn()) {
          $location.path("/signin");
        }
      });

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

My PHP script is not functioning correctly with Ajax

I am currently working with HTML5, PHP, and JavaScript. My goal is to implement Ajax in order to display the sizes of a selected product when an option is chosen from #productoSeleccionado. However, I believe that there may be an issue with my code as the ...

Utilizing Scrollify for seamless section scrolling with overflow effects

I have been experimenting with the Scrollify script (https://github.com/lukehaas/Scrollify) and facing an issue where my sections are longer than the user's screen, requiring them to scroll down to view all content. However, Scrollify doesn't al ...

What criteria should I consider when selecting a JavaScript dependency framework?

When it comes to installing dependencies, how do I determine whether to use NPM or Bower? For example, what distinguishes npm install requirejs --save-dev from bower install requirejs --save-dev? Is there a recommended method, or any guidelines for makin ...

Is there a way to retrieve the dynamically generated text content of an element using document.write?

I am encountering an issue similar to the following: <div id="myDiv"><script>document.write('SOMETHING');</script></div> My goal is to extract the content inside the script tag, which in this case is "SOMETHING" ...

I am encountering an issue where body-parser is not functioning properly with typescript. Whenever I make a request, the request.body is returning as undefined

Below is the code snippet for my Express application using TypeScript version 3.7.4: import bodyParser from "body-parser"; import config from "config"; import cookieParser from "cookie-parser"; import express from "express"; import mongoose from "mongoose ...

Transferring information via a TCP socket in Node.js from an HTML webpage

Hey there! I'm curious about net sockets in Node.js and would love some clarity: I've set up a simple server that echoes back received data. Here's the code: var net = require('net'); var HOST = '127.0.0.1'; var PORT = ...

Display radio options when clicked upon

I am in the process of creating a set of radio buttons that will be utilized for capturing values to generate a subscription/modal checkout. My current situation involves having the radio button options visible. However, I aim to achieve a functionality wh ...

Converting HTML to a Text String (not for display) using Angular

When it comes to displaying HTML in Angular, there are numerous approaches available. For example, using $sce.trustAsHtml(myHtmlVariable) is one way to achieve this. However, I am interested in creating something like the following: myStringVariable = s ...

An animation triggered by scrolling using the @keyframes rule

Is it possible to smoothly animate a variable font using @keyframes on scroll and have it complete the animation loop when the user stops scrolling, rather than snapping back to the starting position? I've managed to make the animation work, but it l ...

Error: Attempting to access the 'useState' property of null object in Next.js

I'm encountering an issue with my custom hooks inside the getStaticProps function while trying to retrieve data from firebase firestore. The error message reads TypeError: Cannot read properties of null (reading 'useState'). Can anyone offer ...

An Angular JS interceptor that verifies the response data comes back as HTML

In my current Angular JS project, I am working on implementing an interceptor to handle a specific response and redirect the user to another page. This is the code for my custom interceptor: App.factory('InterceptorService', ['$q', &ap ...

Text in d3.js vanishing while undergoing rotation

I have been struggling for hours with what seems like a simple problem and haven't made any progress. I'm hoping to receive some valuable advice from the brilliant minds on stackoverflow. You can view my demo at I attempted to use jsfiddle to s ...

Issue encountered when attempting to sign up a user with passport.js

I encounter a "Bad Request" message when attempting to create a new user using Postman with the following content: { "username": "username", "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="07626a666e6b47626a66 ...

Calculate the duration in seconds using the console

Is it possible to display the time of an action in seconds instead of milliseconds using console.time? Below is my code: console.log('start load cache'); console.time('cache load ok executed in') // loading from mongo console.timeEnd( ...

What is the best way to integrate PHP code into my countdown JavaScript code to automatically insert data into a MySQL column once the countdown has reached

I have created a countdown JavaScript code that resets every day at 23:00 of local time. I am wondering if it is possible to incorporate PHP code into this script so that after the countdown finishes each day, it automatically adds "5" to my "Credit" col ...

Insert a zero in front of any single digit hour

What is the best way to add a leading zero before single digit numbers in time format? For example, how can we convert "0:3:25" (hh:mm:ss) to "00:03:25"? ...

Hover over the image with some padding placed around it to see

I am struggling to figure out how to add padding to my image when hovering over it with Onmouseover. I have tried multiple solutions but none seem to be working. Here is the original code: <img src='/wp-content/uploads/2015/04/img-white.png' ...

The design problem arises from using jQuery to dynamically prepare the table body at runtime

The table row and data are not appearing in the correct format. Here is a link to the problem on Fiddle: http://jsfiddle.net/otc056L9/ Below is the HTML code: <table border="1" style="width: 100%" class="eventtable"> <thead style="color: b ...

Troubleshooting a JavaScript Error on an ASP.NET MasterPage

After implementing the following JavaScript code: <script type="text/javascript> $(document).ready(function () { $('#social-share').dcSocialShare({ buttons: 'twitter,facebook,linkedin,di ...

What is the best way to completely clear $rootScope when a user signs out of my application?

In my development work, I frequently find myself using $rootScope and $scope within controllers and services. Despite searching through numerous Stack Overflow answers for a solution to clear all $scope and $rootScope values, such as setting $rootScope t ...