Creating a Spotify-like personal streaming service - Emma Delescolle

This video features Emma Delescolle at DjangoCon Europe 2020 in Online.

Creating a Spotify-like personal streaming service - Emma Delescolle
0:43:51
Published October 15, 2020
729 views

DjangoCon Europe 2020 (Virtual)
September 18, 2020 - 15h10 (GMT+1)

"Creating a spotify-like personal streaming service with Django and Vue: Lessons learned" by Emma Delescolle

In today's web, working with a frontend framework or library is becoming the norm. Vue is one of the most popular ones but how does it play with Django, what are the advantages and caveats? We'll use a practical example to explore some of those, ranging from getting the 2 frameworks to "just" work together to data exchange through a DRF API, authentication and websockets.

Summary

Emma Delescolle explains how she built a personal Spotify-like streaming service with Django and Vue, keeping both applications in one repository. She covers development-server proxying, Vue’s router, components, Vuex and Vuex ORM, Axios, Django REST framework, Django Channels, WebSockets, and session authentication, relating Vue concepts to familiar Django patterns. The application supports playlists, live queues, streaming, search, Last.fm biographies, and downloading songs from YouTube. Her main warning is that streaming mixed MP3 files reliably is difficult without resampling or re-encoding them, while frontend state must be managed carefully because browser data can become stale or consume too much memory.

Key takeaways

  • Vue’s router, application shell, components, computed properties, and CLI can be understood through parallels with Django URLs, templates, inclusion tags, and management commands.
  • A Vue development server can proxy API and WebSocket requests to Django, while Django Channels handles real-time communication on the backend.
  • Axios can handle requests and CSRF settings, and Vuex ORM can cache API models in browser memory with relationships and query-like lookups.
  • Session authentication is a good fit when the frontend and backend share a domain, allowing the application to use Django’s built-in security features.
  • A streaming service cannot safely concatenate arbitrary MP3 files because players may fail when bitrates or encodings change; consistent re-encoding or server-side resampling is needed.
  • Vuex ORM data is part of the Vuex store, so developers must balance fewer API requests against browser memory use and stale local data.

Summarised automatically from the transcript.

Chapters

  1. 0:00 Vue and Django Project Setup Emma introduces the personal Spotify-like streaming project and explains how she organizes the Vue frontend alongside Django.
  2. 2:26 Development Server Integration The talk covers proxying API and WebSocket requests between Vue’s development server and Django.
  3. 3:57 Vue Development Tools Emma presents Vue DevTools, the Vue cheat sheet, and the Vue CLI as essential tools for development.
  4. 6:17 Vue Fundamentals for Django Developers Vue routing, application shells, components, single-file components, properties, data, methods, and computed properties are compared with Django concepts.
  5. 12:25 API Data and Frontend Models The speaker explains connecting Vue to Django REST Framework with Axios, Vuex ORM, Vuex, and frontend model relationships.
  6. 20:05 Real-Time Updates with WebSockets Django Channels and Vue Native WebSockets are used to exchange live playback and queue updates.
  7. 22:24 Authentication The talk compares token and session authentication and demonstrates protecting Vue routes with Django-backed login state.
  8. 25:28 Streaming Service Demo Emma demonstrates playback, queues, music search, artist information, YouTube downloads, and switching between local and live streams.
  9. 29:24 Streaming Challenges and Lessons The conclusions address audio bitrate and encoding problems, Vue’s similarities to Django, frontend data freshness, and mutations.
  10. 32:34 Questions The Q&A discusses Vuex ORM versus direct Axios requests, GraphQL versus Django REST Framework, and offline authentication storage.

Questions this talk answers

How do I run Vue and Django development servers together?

Configure Vue's development server to proxy API and WebSocket requests to Django. Because Vue serves its generated files from memory, a Django URL fallback can redirect unknown URLs to the Vue development server during development.

Discussed at 2:26

What are the Vue equivalents of Django URL patterns, templates, and inclusion tags?

Vue Router plays the role of Django's URLconf, App.vue is the persistent application shell, and components are reusable pieces comparable to inclusion tags. The router maps paths to components, while router-view renders the matched page inside the shell.

Discussed at 6:02

How can I keep Vue single-file components organized when I prefer separate HTML, JavaScript, and CSS files?

Keep the .vue file as a thin wrapper with template, script, and style tags, and have each tag load the corresponding external HTML, JavaScript, CSS, or SCSS file.

Discussed at 9:21

How do I fetch Django data in a Vue single-page application?

Expose the data through an API, commonly using Django REST Framework, then call it from Vue with Axios. Axios can also be configured with Django's CSRF cookie and header so same-domain requests retain Django's security protections.

Discussed at 12:12

What is Vuex ORM and when should I use it with Vue?

Vuex ORM stores API data in an in-browser database-like store, letting the frontend query already-loaded records and relationships before making another backend request. It is useful for reducing repeated requests, but loading too much data can consume memory; for data that should not be stored, use Axios directly in a component instead.

Discussed at 14:37

How do I add live updates to a Vue and Django application?

Use Django Channels on the backend and a Vue WebSocket package on the frontend. WebSocket events such as connection-open and message events can trigger Vuex mutations that update application state.

Discussed at 20:25

Should I use session or token authentication for a Vue single-page app with Django?

Use token authentication when the frontend is served from another subdomain or a CDN. For a same-domain personal application, session authentication is convenient because it lets the app use Django's built-in security features; it requires login and logout endpoints and frontend state updates through mutations.

Discussed at 22:24

How can I protect Vue routes that require login?

Mark protected routes with metadata such as requireLogin, then run a check before every route transition. If the user is not authenticated, redirect them to the login page instead of rendering the requested route.

Discussed at 24:28

Why does a personal audio stream fail when the bitrate or encoding changes between songs?

Many players do not handle a stream whose MP3 bitrate or encoding changes between tracks. The speaker found it worked with Kodi because Kodi resamples the stream; otherwise, the practical options are to resample before streaming or re-encode all files to a consistent format.

Discussed at 29:24

What is the tradeoff between storing Vue data in Vuex ORM and fetching it directly with Axios?

Vuex ORM is part of the Vuex store and avoids repeating backend requests for data already loaded, but storing a large portion of the database can slow the browser and use memory. Direct Axios requests avoid that local storage cost, at the expense of making a new backend request whenever the data is needed.

Discussed at 33:42

Why did you choose Django REST Framework instead of GraphQL?

The speaker prefers Django REST Framework because its API limits users to explicitly permitted requests. GraphQL can be configured safely, but poorly constrained queries may force expensive joins or retrieve too much data and put the backend at risk.

Discussed at 36:12

How can I keep Vuex ORM user data in offline browser storage and verify it later?

Store the user model locally, then when the application opens, call a backend endpoint such as “me” to check whether the session is still valid. A 401/403-style response logs the user out; a successful response is compared with the stored user and updates the local state if necessary.

Discussed at 40:09

Open full transcript Markdown

Transcript

6,032 words · auto-generated · en Show transcript

Automatically transcribed, so expect mistakes in names and technical terms.

Emma Delescolle

Hello and welcome to this three minute talk for Django. con Europe 2020. Today we will be talking about my experience trying to create a Spotify-like streaming service for personal use with Django EnView So first of all, who am I? My name is Emma. I am the co-founder of a small company in Belgium called Levit. And I'm the maintainer of the Aroschema Adapter as well as Ember Clive Fiddles and other libraries. So if you've known me and seen me at other conferences, you might be wondering, are you sure you want to talk about view?

You usually talk about amber. But yeah. I've been smitting talks about l about amber for a few years now and they always get rejected. So I thought, hey, let's try something else and let's try a few. But all that said, I will be at some time comparing View to Amber So first I had to get started and being a full stack developer I like to have my front end in the same repository as my back end So to do that, I wanted to have my frontend at the same level as any Django application that would be my project. And this is what we have on the screen here. To get to that point, all I had to do was to install a Vue

CLI, which is the CLI tool for View. We will talk more about it later. And once that was done, I just had to type View Create Front, front being the name of my front-end application. And this is what I got. So on the front you see there are three directories. There's source, there's tests, and there is public. Public is for any resources like images and things like that. Source is where the main code will be and test of course is for tests So the first issue I encountered was to try to have the two servers to talk nicely together because Django has its own development server, but Vue

also has a development server with reload and other nice features. So to do that, you can see that you have a config file for view in which you can specify some information. That config file is used for view and it is later transformed to be used by Webpack as well. So the server is actually not directly from Vue. And you can see here that we are proxying every request to Django, every API request to Django, and also every WebSocket request to Django as well. So the other way around I'm used with Amber

and the Ember Development Server whenever you make a modification it recompiles everything and writes files to disk. So The only thing that you have to do on the Django side is to create a template view that will just fetch the index. html that is created by Ember. This is not the case with Vue. Vue creates all the files, all the temporary files in memory and serves those files directly from memory. This means that there is no way from ja for Django. to go fetch the file and display that as a template view. So an alternative to be at ease in development is to just redirect every have a casual

URL in your Django URLs and redirect everything that is not known towards the view development server After that, I wanted some tools to be able to work with you and one of the major tools that I found was the browser extension. which is available for Firefox as well as Chrome. There is a similar tool for tool for Amber, Vact, Angular. So I knew something like that existed. You can go and get it from the web store for Chrome or for Firefox and you can see here on the screen that it

shows you every single component that is rendered in view. If you focus on a component in particular, you can have its properties, its data, everything like that. There are several tabs to look at what happens in different parts of you. The next thing that I found really, really useful was the cheat sheet. There is this PDF that's two pages long. And that has all the life cycles of all the components, how to pass properties, all the syntax you have to use and all that. That cheat sheet is available at the URL that you see on your screen. And it is honestly one of the most useful tools that you can have if you're either new to Vue

or if you have not used Vue for a long time Or even if you use Vue along other front-end frameworks because it's easy to get confused between one and the other And finally, the next thing that is really useful is a CLI tool. So it's like manage. py for Django. You can use it to create new project to build your project to launch the development server you can add new tasks you can also add some blueprints to your project. So for example if you didn't select tests and you want to add tests you can add test on the fly to the project and things like that. So once again very, very useful.

So before we go any further, let me ch give you a few basics of view for Someone who is coming from the Django world. So there are two ways to use Vue. You can either include the JavaScript of Vue in any regular Django server rendered view and it will load like any other any other JS, like Bootstrap for example. But in this case I wanted a single page app, so this means that my application, my front end application is gonna have different routes and for that I do have a file that's called rotor. js or router slash index. js And this is basically the same as the URL.

py. It's going to match the URL and send it to the correct view component. Next we have app. view. App. view is very similar to your templates bash HTML. This is the shell of your application. This is where you're going to put your menus, your headers, your footers, everything that has to always be on the page. This is where it's gonna go. And finally you have components. Components, if you want to compare to something in Django, are like super inclusion tax. There are inclusion tags that are used everywhere. Every single page is usually a component, so it's

top level. Is going to be included inside your app. pht ml So let's look a little bit deeper in those files. So as I mentioned, router. js or router slash index. js is the same thing. As far as JavaScript is concerned, it's a bit like if you have some module dot py or if you have some module some module and inside that directory you have dunder init dunder That's exactly the same technique. If you look at this file, you can see that the URLs are defined pretty similarly to Django. So there is a path.

This to match the URL. There is a name which is optional, and there is a component which in Django would be associated to the view function. That's going to be actually rendering the content of your page. Then there is this app. view file. So, first of all, what is a. view file? That's something we don't know. It's a file extension that is specific to view and it's a bit messy in the way that it has HTML inside of a template tag, it's got JavaScript. inside of a script tag and it's got some CSS or SCSS

inside of a style tag but we don't like that in Django. In the Django world we like to have things clean in different files. So one way to fix that is to keep using the dot view application and have really simple. View files that have three tags, one template that loads an HTML file one script tag that loads a JavaScript file and one style tag that loads either CSS or an SCSS file Here on the screen you can also see on the bottom left the HTML for this app. view And inside its

HTML there are two important things. There is the first div that's the ID app. This is where view will know it has to render. It will replace the div with the ID. The ID app and inside of that you can see that you have a router view. The router view is where The rest of your page that corresponds to the URL that you have been loading, the rest of your page is going to be rendered inside that tag. So those are the two most important tags in the View application. Now there's a component. js. It comes with some

some information so you have properties, properties are things that are passed to the component usually from another component that a parent component that calls a child component and passes some variables. Once again same principle as templates an inclusion template type You have some data, the data is local to the component, and you have some actions. You have some methods. Methods are being called from inside the component. They can modify the data of the component itself. And finally you have computed properties. Computed properties I used so that you don't have to do complex logic in code.

So for example, here we have two computed properties that are going to be dependent on the z data and when the sp data changes those two computed properties will also change And so if we look at the HTML for the template for that for that component, you can see that we do use the data is pz. And we also use some of the computed properties. So you can see here we are using columns. Disabled so this is an assignment to an HTML property and so

This means that the disabled property is going to come from JavaScript We have an at click. At is for events. So when the button is clicked, it's going to be calling The method that is listed here, which is download, and then underneath we have some other assignments with the computed properties so now that we have gone through the basics of Hue, we can look at something more interesting like How can we get data from Django to Hue? So in this case, in single page application, there is no way to have Django

pre-render the data somewhere in a JavaScript variable or something. So you have to call an API. And so as most Django projects, when you want to have an API, you are going to want to use Django Rest framework. So these are examples for a serializer in a view set for Django West framework. But since I mentioned I was the maintainer of the ARS Schema Adapter. I'm going to use the Reschema adapter and so here is an endpoint that does exactly the same as the two previous view set and serializer. plus a few extra features like searching and filtering. Now on the view side

There are different ways to do things. The way I found what's the most familiar to me as a Django developer or an Amber developer was to use series of things. First of all Axios. Axios is a library that does HTTP requests. It can be used with Vue, it can also be used with React, or it can even be used standalone. Axios just needs to be initialized. It takes a URL to start with and here we can see also the two last lines that are the configuration for the X SRF token and header

This is really useful if you're serving your front end from the same server as your backend and from the same domain. This means that you're going to be using Django's all of Django's security features. features including but not limited to CSURF tokens. So you have to specify those information in the connection and Axios is going to handle that completely transparently. Next to Axios, we are going to be using VuexORM. ViewX RM is an RM like Django's ORM the difference is that it's going to be storing some data inside your browser 's

database and it's every time you add some data from the API or from somewhere else It's going to create basically a SQL database just in memory in your browser, which is really useful, for example, if you already have loaded a bunch of artists and you need to look up an artist in particular, you can just first check in memory if you have that artist before doing an API call to the back end You can do requests like you would do in SQL with sword statements and things like that. And here you can see how you register

Vue XRM What you need to do is you need to have a model definition for all your models and then you simply register them to the database. The last thing we're going to be looking at is Vuex. Vuex is state management storage for View. It is used by Vuex RM since it's in the name. It's also the standards used with Vue. And here is the configuration to have it installed and as you see you can register plugins and in this case the plugin that we want to register is the RM

And finally, as far as the data exchange is co is concerned, we have the models This is the artist model and as you can see it is very similar to a Django model. So you what you do is that you list the properties, the fields of that model. Of course you don't have as many choices as you have in Django. You basically have string, number, date, Boolean, and undefined, which is the dot adder. But you do have interesting things like one too many relationships. So for example, if you look here you see that the artist has many songs and this is a relationship

works to say moi as a Django relationship. Or anything else, you can just access it with the dot notation. You can see at the beginning of the file that I'm inheriting from a base. js file. So this is a snippet from the base. js file. It's it's got some methods that are used everywhere like fetch all, fetch by ID, filter, things like that. Since this is something that you are going to be using with all your models, I like to have it in the base. js, but if you are using the Aeroschema adapter You can export all your endpoints, your back-end endpoints, directly to front-end

models and it will write the best. js for you, and it will write your models also with every property and so on. So accessing the data in the front end, in the template As I mentioned, it works exactly like Django, you can use the dot notation. So for example, if you look into this one, we have a list And it's gonna loop over the artist. songs, so all the songs of the artist. And once we have the song, we can use the song dot

Some dot file to get the file for example and but you have to be careful In order to be able to use the dot notation, you have to warn the URM that you want to load the artist with the song. So if you look at the JS codes at the bottom of the screen, you will see that it is specifying that it loads with Song. It also has a word statement to filter the results. And if you don't use that whiz, it will not have access to the songs and you will run into trouble. This is a nice way to avoid things like n plus one

requests. This is This can be seen either as a blessing or the or a curse, but it's how it works Next, if you want to write a single-page application nowadays, most likely you are going to be having some live data. So for example, in this application, which is a streaming service, you want to update the currently playing song, you want to update the list of coming up next songs and all that. So for that you need a web socket. For Django, on the Django site I picked Django channels and here's the configuration for Django channels It's a very standard Django

channels configuration. Note that we are using the authentication stack in here, which is always a nice thing. And on the View side, there is a package that's called View Native Sockets, which is really handy. What you have to do is to declare the socket with some the URL is going to connect to some properties and then the socket is going to be emitting some events and once an event is emitted it's going to call a transform

or a mutation. So here for example when the connection is open the mutation socket on open is called and it's going and you can perform things on open on message on things like that Mutations is a concept which is really important in view. It's about the same concept as is in React. This is how you change data. You cannot just simply take some data and change it in like in Django you have to go through mutation which is a concept that I'm not going to explain today because I don't have the time But if you are going to be using React or Vue, you really need to go in there and understand mutations.

Next step is authentication. This is useful since I want to be able to create my playlist. I don't want to see my partner 's playlist. and things like that. So it's important that my application has some authentication. So authentication, there are basically two ways to do that for a front-end single page application. Either you can go with token, which is the preferred way to do things if your front-end application is served from another subdomain. then your main application. If you are using a CDN or something like that to serve your front end, you will want to use tokens. But since I this is a personal project And since I'm a full-side

developer, I want I like to use the session authentication because that way I can once again leverage all the security tools that Django provides out of the box. So to have section authentication working on the Django side, you don't need much, you just need a login and a logout view That are going to be the logging view is going to take a username, a password, it's going to check it using the regular Django contrib. org tool and is going to return a user. On the view side, a little bit more code is needed, but not that much.

You have We have here some actions that are defined in the store. So we have been seeing a lot of code that is in the store. So the store is what has to do with all the data. that view receives or view handles in one way or another. So here in the store we have two actions which are login and logout And upon a successful login we are calling immutation, which is old success, and that old success is going to update the user that is stored in memory in view. So one once again this is a mutation this is really important to use mutations

But that's that's the gist of it. So login function, logout function, and then immutation to be able to update your user on the front end. And once your user is updated in the front end, you can use it in a lot of locations. One of the most useful locations is in the router, for example. So here you can see a route like the ones that we saw in the beginning, but this one has meta information. This is this which means require login. Which is called require login. And so you can see at the bottom of the screen there is this code that is run before each transition

from one route to another route and it will check if that route needs authentication and if the route needs authentication will check if the user is authenticated and if the user is not authenticated it will redirect the user to the login page instead of showing them the page that they were that were they were asking to see So now we're going to be doing a demo. And Here we have our application. It's got a queue of things that are playing.

and this queue is always fed to a stream, so if I click play right now, I will be connecting to the stream Which is if you recognize the song, it is the one that is said he's playing. So what Why did I want a stream? I wanted a stream so I can be listening to a playlist on my computer and then go to the living room and switch on my media player and retrieve the stream or where it was playing. No, this is not this is of course not the only thing that

this thing do. You can search for information. So I just searched for girl, I got an artist, I got several songs. With these songs I can just add them to the playlist. For example, if I go look at an artist, this one doesn't have any songs. But if I go look at Madonna, I see that I have two songs from Madonna. I also have her full biography, which comes from Last FM since this is for personal use, something else I wanted was to be able to download things from

From YouTube so I can make a search on YouTube and here is I I've got my YouTube search results. Once I have them I can download one of the songs This is going to take a minute or two and once the song is going to be downloaded, it's going to be available in my playlist and this is the demo effect this one didn't download let me try to download another one Maybe all my bandwidth is being taken by the stream from the from the conference. I'm not sure Let's see what happens here. Yes, the song has been downloaded and now I can just click play

and here is my song play. So this is playing completely independently from the st from the from the stream. And if I want to go back to the stream, I can just reconnect to the stream and Get back to my regular stream. This works completely independently and yeah here is the stream that's back up It is still playing the same song. And I guess that's about it for the demo.

So now let's move to the conclusions. So the conclusion is that streaming is hard. The major issue I got with this with this application is that I thought I thought I could just push every mp3 song to the stream and it would work correctly and it happens that it doesn't work correctly it just works correctly with one player which is Cody because Cody does a resampling of the stream before playing it locally. Other stream players have difficulties with having the stream when changing from one mp tree to the next, changing bit

rates or changing encoding or things like that. So the stream finally is the is the worst part of it. Right now it's still It's still not working properly except on Cody, which is an issue. But yeah. Unless I ask Django to do the same work as Cody and resample everything before streaming. I don't see that there's a good solution to that except re-encoding all my MP trees myself to make sure that they are of the same The same bitrate and everything. The next conclusion is that as you've seen, Vue

is not that different from Django. If you are using the tools that I showed you, You can easily go from Django to View, yes, it's JavaScript, it's another language, but it really uses the same concepts as Django. And the another thing you have to be looking at, of course, is the data Don't forget that while we're using a VXRM you are going to be using local data and the local data is not always the same. as the data in the back end so you have to make sure to refresh that data often. And finally mutations. Mutation is a concept that

is completely referring to Django developer, maybe you can try to think about it like if you are changing information on a model in a view on Django it will not it will not be in the database accessible to another view until you push the save you call the save method So that's a mutation. And I've run a little bit over time, so we can now go to the Q<unk>A And that's it for the talk. Thank you for listening. Thank you to the organizers who did a really wonderful job and were really understanding of technical issues.

Okay, so next one

Speaker 2

Yeah, I have some about the ORM. Like I never worked with that, so no I don't much idea how this RM in the front end works. But I suc suspect is it should be more like efficient or some way, instead of using like a store. I guess the view store is something similar with the store we use in React I mean it's like a huge data object with like all the data you have in memory. So like do you have an any idea of like w a guideline to choose between like I want

us this data of mine stored in this or in the front end or as like in the store objects Yeah.

Emma Delescolle

CRM D O RM is part of the store object. So if you're using DRM, you are going to be using the store. It's a double-edged sword. So if you start loading a bunch of data, if you load your entire back-end database in the front end Your browser is going to be slow, is going to be using a lot of memory, that's not going to be good. Although if you look at most Postgres databases, for example a lot of them could actually be running in memory on most computers nowadays. If you're using Chrome, anyway you're using

four or eight gigs of RAM just for Chrome. So it's it's it might not be that much of a problem because that store is going to be removed whenever you close the page. No, if you really don't want to use that all that memory, you can directly use Axios, which is the part that does HTTP requests and you can just directly use Axios in your view component to load the data. not put it in the store and use it directly in your component. That way it's not going to be stored inside that store but this means that every time you will need that data you will have to do a back-end request which is going to

be taking a lot more resources than just going back to the store if this is something that you already have loaded in a previous request

Speaker 2

Cool.

Emma Delescolle

Okay, so if that answers your question, I don't know who's next.

Speaker 3

Well I have a question.

Emma Delescolle

Yes.

Speaker 3

Yes, hello. I'm Jens from the Pacific Institute. We are also going to implement yeah. js together with Django and but now we are going for GraphQL do you have any idea or what why did you choose Django Rest framework over GraphQL or do you do you have any tips on that or what should be different

Emma Delescolle

I do not have some tips on GraphQL. My personal take on GraphQL is that I do not like it The reason I do not like it is that it's really easy for anybody to forge a request in GraphQL that will just completely kill your back-end server. It is possible in GraphQL to ask from some data to force the backend to make some joints on the database. And you if you craft if you look at the requests that go by in the browser and you craft something you can request the whole database at once with GraphQL

This is there are mechanisms in GraphQL to prevent that from happening. But in GraphQL if you're writing your API in GraphQL you do have to always have that information in mind, that security concerns you always have to have that in mind, which is something that you don't need to have in mind with Django Rest framework because you can the user can only request whatever you say that they can request. So this is why I usually go for rest Django REST framework and not GraphQL. So I've not looked into the GraphQL options and I'm sure there are some perfectly nice libraries in View to use GraphQL, but I cannot help you with that

Speaker 3

Okay, thank you, but it's also good information. Well I I've also experience with Django REST framework. Okay, then we can think about it. Okay, thank you very much for this information.

Emma Delescolle

You're welcome. Next person. I see Adam is next on my screen.

Speaker 4

Yeah, I've I think everyone's questions look good.

Emma Delescolle

Okay next on my screen is Zirina Verena, you are muted. Okay, so no question from the reina. Next is Telmo. Okay, no question from Thelma. Volker?

Speaker 5

No, I didn't really have a question. I was interested actually in the thing that you were showing now, synchronization with the with the backend. But I think the yeah, the base model you're coming up now of answering that. So thank you

Emma Delescolle

Welcome.

Speaker 5

I'm sorry, this was for Volca. I thought you said Wouter, which is my name.

Speaker 6

Oh don't worry.

Emma Delescolle

It's okay.

Speaker 6

Okay, may I? It's Folker. I was too slow to unmute my microphone. I have a question with regards to the VuexRM and the local forage plugin The local forage plugin allows to use the indexed db in the browser for offline storage. Do you have any experience with storing offline data using this combination?

Emma Delescolle

Yes. Most of the time the data I want to store offline is the user information. So as I said, when you log in you receive the info the user information. So something I do is that I store the user information locally on the browser. So next time and offline so next time you use you open that page I look into the information I say oh we already have a user so let me just try to Make a request to the backend and see if you're still authenticated. Since we're using session authentication. So it there is I have an endpoint that is called me

And so what I do is that with this information I make an a call to the backend, to that endpoint, either I get a four or three response, which means that I'm not authenticated on the back end anymore. Either I get a 200 response if I get a 200 response and the data from that response is different from the user that I have stored in the offline storage. I will log out the user And if the if the data is the same I will keep the user on and so the that user can be Usually I've got a user model and I'm storing the user model from the Vue XRM

data.

Speaker 6

Okay, that's quite nice. Do you use token authentication in any project that you do?

Emma Delescolle

I do use token authentication but not in any view project currently.

Speaker 6

Oh sorry.

Emma Delescolle

No, it's it's okay. I'm probably going to use one starting next week. But so far I've been using token authentication on other projects that were using Angular, React, and Ember, but I don't think I've ever done one with you. It's pretty similar from what I've read. It's pretty similar to any other front end authentication. Framework so there are libraries for using odds for example or if you are using the Django rest framework Token, so the permanent token. You can use that. I'm going to go back.

Yes.

Speaker 6

Yes. I do use token based authentication in a project.

Emma Delescolle

Yes.

Speaker 6

So if you are interested in an exchange besides this web conference right now then you can c contact me on slack.

Emma Delescolle

Okay.

Speaker 6

because I'm using j Django Nox Because the base token authentication of Django Rest framework allows only for one token and that is not encrypted in the database. So we changed to Django REST mocks in this case because there can be multiple tokens and they are encrypted in the database.

Emma Delescolle

Okay, best thanks.

Speaker 6

Okay. Thank you very much.

Emma Delescolle

Thank you. And so

Conference

DjangoCon Europe

September 18 - 19, 2020

Online

Note: We understand that names change, people change, and bodies change. We respect each individual's journey and privacy. If you have any concerns about a video or need us to remove content, please don't hesitate to contact us. We will handle your request with care and promptly address any issues.

More videos by Emma Delescolle

More videos from DjangoCon Europe