0

I have a frontend using Vue.js and a backend using Java Spring.

I'm trying to get the Windows Username and display it.

So for this, I activated my front end server as an Intranet server in my Windows params. I saw here that there's a possible way to get the windows username with IIS by activing this option.

But it is possible, with Vue.js, to get it without using IIS or any other way?

Louis Chopard
  • 334
  • 1
  • 11
  • 2
    Vue.js is frontend JS, there's no way you can get the windows username with just in-browser JS. A backend can easily get the username. –  Jun 02 '22 at 14:19
  • I tried but how can get that username since my backend is in a server(and my frontend is a client)? I was only able to get server's username – Louis Chopard Jun 02 '22 at 14:29
  • 1
    Does this answer your question? [How to get the name of the current Windows user in JavaScript](https://stackoverflow.com/questions/9518092/how-to-get-the-name-of-the-current-windows-user-in-javascript) – Peter Krebs Jun 02 '22 at 14:31
  • You cannot get the client's username. –  Jun 02 '22 at 14:31
  • Do you know any way to solve my problem? Any docs? Or to help me to understand better – Louis Chopard Jun 02 '22 at 14:36
  • 2
    The reference to the backend in this context means that some backend process needs to run on user's machine in order to provide the frontend with this info. This is the case for Electron, etc desktop framework. It would be a huge security threat if this were possible with browser api alone. – Estus Flask Jun 02 '22 at 14:37
  • There is nothing to understand here. While the browser in theory has full access to the user's hard drive, the JavaScript code running inside it has not. Otherwise websites would be able to steal all of your data. It's simply not possible to get the username from in-browser JS, *period*. Asking about ways to solve this is not going to magically produce them. –  Jun 02 '22 at 14:46
  • @ChrisG Yes. I understand that. I mean an alternative to solve this ? Sharepoint, GLPI, etc... gives the possibility to auto-login with an AD by getting your username in an intranet context. – Louis Chopard Jun 02 '22 at 14:49
  • If this question is about keeping people logged in, why not simply use a session cookie that doesn't expire for a year or so? –  Jun 02 '22 at 17:31
  • @ChrisG This is question is not only about keeping people logged in. I wanna auto-log them with their Windows account the same as sharepoint, glpi and many other intranet plateforms. – Louis Chopard Jun 03 '22 at 06:28
  • Yes. So write an actual executable application that can easily do that. You are writing an in-browser Vue app so you CANNOT. PERIOD. The answer to your question is: "NO". Please accept it and move on. –  Jun 03 '22 at 07:56

1 Answers1

1

If you do not want to use Microsoft Auth you can set a environment variable when you launch your app from server, and then you can access your user name variable from process:

export default {
   name: 'PageOrComponent',
   data() {
     return {
       userName: process.env.USER_NAME
     }
   }
}
thebyteland
  • 359
  • 1
  • 2
  • 10
  • That's the *server's* username though. OP is looking for the *client's* –  Jun 02 '22 at 14:32
  • Data must always be provided from backend for security reasons. You can not access from a random web app to Windows data. But if your servers knows the userName, it can be provided to client with environment variables, services, APIs... – thebyteland Jun 02 '22 at 14:42
  • I know all that, I'm explaining to you why your answer isn't an answer to OP's question and should be removed –  Jun 02 '22 at 14:44