mirror of
				https://github.com/livebook-dev/livebook.git
				synced 2025-10-31 15:56:05 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			18 lines
		
	
	
	
		
			485 B
		
	
	
	
		
			Elixir
		
	
	
	
	
	
			
		
		
	
	
			18 lines
		
	
	
	
		
			485 B
		
	
	
	
		
			Elixir
		
	
	
	
	
	
| defmodule LivebookWeb.SessionIdentity do
 | |
|   # This module implements the ZTA contract specific to Livebook cookies
 | |
| 
 | |
|   import Plug.Conn
 | |
| 
 | |
|   def authenticate(_, conn, _) do
 | |
|     if id = get_session(conn, :current_user_id) do
 | |
|       {conn, %{id: id}}
 | |
|     else
 | |
|       user_id = Livebook.Utils.random_long_id()
 | |
|       {put_session(conn, :current_user_id, user_id), %{id: user_id}}
 | |
|     end
 | |
|   end
 | |
| 
 | |
|   def child_spec(_opts) do
 | |
|     %{id: __MODULE__, start: {Function, :identity, [:ignore]}}
 | |
|   end
 | |
| end
 |